mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-12 05:08:23 -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. -->
71 lines
2.0 KiB
Swift
71 lines
2.0 KiB
Swift
import HAKit
|
|
@testable import HomeAssistant
|
|
import PromiseKit
|
|
@testable import Shared
|
|
import XCTest
|
|
|
|
class OnboardingAuthStepModelsTests: XCTestCase {
|
|
private var step: OnboardingAuthStepModels!
|
|
private var api: HomeAssistantAPI!
|
|
private var connection: HAMockConnection!
|
|
private var sender: UIViewController!
|
|
private var modelManager: FakeModelManager!
|
|
|
|
override func setUp() {
|
|
super.setUp()
|
|
|
|
modelManager = FakeModelManager()
|
|
Current.modelManager = modelManager
|
|
|
|
connection = HAMockConnection()
|
|
api = HomeAssistantAPI(server: .fake())
|
|
api.connection = connection
|
|
sender = UIViewController()
|
|
|
|
step = OnboardingAuthStepModels(api: api, sender: sender)
|
|
}
|
|
|
|
override func tearDown() {
|
|
super.tearDown()
|
|
|
|
Current.modelManager = .init()
|
|
}
|
|
|
|
func testSupportedPoints() {
|
|
XCTAssertTrue(OnboardingAuthStepModels.supportedPoints.contains(.afterRegister))
|
|
}
|
|
|
|
func testPerformSuccess() {
|
|
modelManager.fetchResult = .value(())
|
|
modelManager.expectedApis = [api]
|
|
let result = step.perform(point: .afterRegister)
|
|
XCTAssertNoThrow(try hang(result))
|
|
}
|
|
|
|
func testPerformFailure() {
|
|
modelManager.fetchResult = .init(error: TestError.any)
|
|
modelManager.expectedApis = [api]
|
|
let result = step.perform(point: .afterRegister)
|
|
XCTAssertThrowsError(try hang(result)) { error in
|
|
XCTAssertEqual(error as? TestError, .any)
|
|
}
|
|
}
|
|
}
|
|
|
|
private enum TestError: Error {
|
|
case any
|
|
}
|
|
|
|
private class FakeModelManager: LegacyModelManager {
|
|
var fetchResult: Promise<Void> = .value(())
|
|
var expectedApis: [HomeAssistantAPI] = []
|
|
|
|
override func fetch(
|
|
definitions: [FetchDefinition] = FetchDefinition.defaults,
|
|
apis: [HomeAssistantAPI] = Current.apis
|
|
) -> Promise<Void> {
|
|
XCTAssertEqual(expectedApis.map(\.server), apis.map(\.server))
|
|
return fetchResult
|
|
}
|
|
}
|