mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-11 20:27:50 -05:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> This PR will change the approach of how the app keeps it's data updated by not subscribing to all state changes and only periodic updating it's app entities instead. This will avoid several issues where users experience their app to freeze due to 9k entities updating every second and notifying the app. ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
81 lines
2.2 KiB
Swift
81 lines
2.2 KiB
Swift
import HAKit
|
|
@testable import HomeAssistant
|
|
import PromiseKit
|
|
@testable import Shared
|
|
import XCTest
|
|
|
|
class OnboardingAuthStepNotifyTests: XCTestCase {
|
|
private var step: OnboardingAuthStepNotify!
|
|
private var api: HomeAssistantAPI!
|
|
private var connection: HAMockConnection!
|
|
private var sender: UIViewController!
|
|
|
|
override func setUp() {
|
|
super.setUp()
|
|
|
|
// kill off any existing observers for this test run
|
|
Current.onboardingObservation = .init()
|
|
|
|
connection = HAMockConnection()
|
|
api = HomeAssistantAPI(server: .fake())
|
|
api.connection = connection
|
|
sender = UIViewController()
|
|
|
|
step = OnboardingAuthStepNotify(api: api, sender: sender)
|
|
}
|
|
|
|
func testSupportedPoints() {
|
|
XCTAssertTrue(OnboardingAuthStepNotify.supportedPoints.contains(.complete))
|
|
}
|
|
|
|
func testPerform() {
|
|
let notificationExpectation = XCTNSNotificationExpectation(
|
|
name: HomeAssistantAPI.didConnectNotification,
|
|
object: nil
|
|
)
|
|
let observationExpectation = expectation(description: "observation")
|
|
|
|
let observer = FakeOnboardingStateObserver(expectation: observationExpectation)
|
|
Current.onboardingObservation.register(observer: observer)
|
|
|
|
let result = step.perform(point: .complete)
|
|
XCTAssertNoThrow(try hang(result))
|
|
wait(for: [
|
|
notificationExpectation,
|
|
observationExpectation,
|
|
], timeout: 10.0)
|
|
|
|
withExtendedLifetime(observer) {
|
|
//
|
|
}
|
|
}
|
|
}
|
|
|
|
private enum TestError: Error {
|
|
case any
|
|
}
|
|
|
|
private class FakeOnboardingStateObserver: OnboardingStateObserver {
|
|
let expectation: XCTestExpectation
|
|
init(expectation: XCTestExpectation) {
|
|
self.expectation = expectation
|
|
}
|
|
|
|
func onboardingStateDidChange(to state: OnboardingState) {
|
|
if case .didConnect = state {
|
|
expectation.fulfill()
|
|
}
|
|
}
|
|
}
|
|
|
|
private class FakeModelManager: LegacyModelManager {
|
|
var fetchResult: Promise<Void> = .value(())
|
|
|
|
override func fetch(
|
|
definitions: [FetchDefinition] = FetchDefinition.defaults,
|
|
apis: [HomeAssistantAPI] = Current.apis
|
|
) -> Promise<Void> {
|
|
fetchResult
|
|
}
|
|
}
|