mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Fix more unit tests. (#1406)
- Randomise test order. - Use deferred fulfilment in more places. - Make sure to change something before awaiting the fulfilment. - Build a fresh AppSettings after reset(). - Retry tests on failure.
This commit is contained in:
@@ -20,18 +20,20 @@ import XCTest
|
||||
|
||||
@MainActor
|
||||
class AnalyticsSettingsScreenViewModelTests: XCTestCase {
|
||||
private var appSettings: AppSettings!
|
||||
private var viewModel: AnalyticsSettingsScreenViewModelProtocol!
|
||||
private var context: AnalyticsSettingsScreenViewModelType.Context!
|
||||
|
||||
@MainActor override func setUpWithError() throws {
|
||||
AppSettings.reset()
|
||||
appSettings = AppSettings()
|
||||
let analyticsClient = AnalyticsClientMock()
|
||||
analyticsClient.isRunning = false
|
||||
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
|
||||
appSettings: ServiceLocator.shared.settings,
|
||||
appSettings: appSettings,
|
||||
bugReportService: ServiceLocator.shared.bugReportService))
|
||||
|
||||
viewModel = AnalyticsSettingsScreenViewModel(appSettings: ServiceLocator.shared.settings,
|
||||
viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings,
|
||||
analytics: ServiceLocator.shared.analytics)
|
||||
context = viewModel.context
|
||||
}
|
||||
@@ -41,13 +43,13 @@ class AnalyticsSettingsScreenViewModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testOptIn() {
|
||||
ServiceLocator.shared.settings.analyticsConsentState = .optedOut
|
||||
appSettings.analyticsConsentState = .optedOut
|
||||
context.send(viewAction: .toggleAnalytics)
|
||||
XCTAssertTrue(context.enableAnalytics)
|
||||
}
|
||||
|
||||
func testOptOut() {
|
||||
ServiceLocator.shared.settings.analyticsConsentState = .optedIn
|
||||
appSettings.analyticsConsentState = .optedIn
|
||||
context.send(viewAction: .toggleAnalytics)
|
||||
XCTAssertFalse(context.enableAnalytics)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user