Files
element-x-ios/UnitTests/Sources/AnalyticsSettingsScreenViewModelTests.swift
T
Doug 93825c01ad Initial implementation of AccountSettings. (#6275)
* Make the UserPreference macro also generate an accessor for the key name.

* Initial implementation of AccountSettings.

- Add an AccountUserDefaults storage with a userID prefix on the key.
- Migrate the 2 values reset by AppSettings.resetSessionSpecificSettings to AccountSettings.

* Rename UserSettings.volatile() to UserSettings.mock()

Given it now has a userID parameter with a default value..
2026-10-06 17:52:24 +01:00

50 lines
1.5 KiB
Swift

//
// Copyright 2025 Element Creations Ltd.
// Copyright 2022-2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
@testable import ElementX
import Testing
@MainActor
final class AnalyticsSettingsScreenViewModelTests {
private let appSettings: AppSettings
private let analytics: AnalyticsService
private var viewModel: AnalyticsSettingsScreenViewModelProtocol!
private var context: AnalyticsSettingsScreenViewModelType.Context!
init() {
appSettings = AppSettings.volatile()
let client = AnalyticsClientMock()
client.isRunning = false
analytics = AnalyticsService(client: client, appSettings: appSettings)
viewModel = AnalyticsSettingsScreenViewModel(userSettings: appSettings.userSettings(for: "@me:matrix.org"),
analytics: analytics)
context = viewModel.context
}
@Test
func initialState() {
#expect(!context.enableAnalytics)
}
@Test
func optIn() {
appSettings.analyticsConsentState = .optedOut
context.send(viewAction: .toggleAnalytics)
#expect(context.enableAnalytics)
}
@Test
func optOut() {
appSettings.analyticsConsentState = .optedIn
context.send(viewAction: .toggleAnalytics)
#expect(!context.enableAnalytics)
}
}