2023-04-18 09:33:32 +02:00
|
|
|
//
|
2024-09-06 16:34:30 +03:00
|
|
|
// Copyright 2022-2024 New Vector Ltd.
|
2023-04-18 09:33:32 +02:00
|
|
|
//
|
2025-01-06 11:27:37 +01:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
// Please see LICENSE files in the repository root for full details.
|
2023-04-18 09:33:32 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
|
|
|
|
@testable import ElementX
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
class AnalyticsSettingsScreenViewModelTests: XCTestCase {
|
2023-07-27 12:38:48 +01:00
|
|
|
private var appSettings: AppSettings!
|
2023-04-18 09:33:32 +02:00
|
|
|
private var viewModel: AnalyticsSettingsScreenViewModelProtocol!
|
|
|
|
private var context: AnalyticsSettingsScreenViewModelType.Context!
|
|
|
|
|
2023-09-26 13:28:29 +03:00
|
|
|
override func tearDown() {
|
2024-03-21 14:01:23 +02:00
|
|
|
AppSettings.resetAllSettings()
|
2023-09-26 13:28:29 +03:00
|
|
|
}
|
|
|
|
|
2023-04-18 09:33:32 +02:00
|
|
|
@MainActor override func setUpWithError() throws {
|
2024-03-21 14:01:23 +02:00
|
|
|
AppSettings.resetAllSettings()
|
2023-07-27 12:38:48 +01:00
|
|
|
appSettings = AppSettings()
|
2023-04-18 09:33:32 +02:00
|
|
|
let analyticsClient = AnalyticsClientMock()
|
|
|
|
analyticsClient.isRunning = false
|
2023-06-23 09:56:22 +03:00
|
|
|
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
|
2024-05-30 14:10:51 +03:00
|
|
|
appSettings: appSettings))
|
2023-04-18 09:33:32 +02:00
|
|
|
|
2023-07-27 12:38:48 +01:00
|
|
|
viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings,
|
2023-06-23 09:56:22 +03:00
|
|
|
analytics: ServiceLocator.shared.analytics)
|
2023-04-18 09:33:32 +02:00
|
|
|
context = viewModel.context
|
|
|
|
}
|
|
|
|
|
|
|
|
func testInitialState() {
|
|
|
|
XCTAssertFalse(context.enableAnalytics)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testOptIn() {
|
2023-07-27 12:38:48 +01:00
|
|
|
appSettings.analyticsConsentState = .optedOut
|
2023-04-18 09:33:32 +02:00
|
|
|
context.send(viewAction: .toggleAnalytics)
|
|
|
|
XCTAssertTrue(context.enableAnalytics)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testOptOut() {
|
2023-07-27 12:38:48 +01:00
|
|
|
appSettings.analyticsConsentState = .optedIn
|
2023-04-18 09:33:32 +02:00
|
|
|
context.send(viewAction: .toggleAnalytics)
|
|
|
|
XCTAssertFalse(context.enableAnalytics)
|
|
|
|
}
|
|
|
|
}
|