Files
letro-ios/UnitTests/Sources/AnalyticsSettingsScreenViewModelTests.swift
Mauro d005243e31 Implemented message forwarding for media previews and media timelines (#4579)
* implemented message forwarding for media previews and media timelines

* updated tests

* pr suggestion

* fix tests

* fix tests
2025-10-07 14:34:14 +02:00

55 lines
1.7 KiB
Swift

//
// Copyright 2022-2024 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.
//
import XCTest
@testable import ElementX
@MainActor
class AnalyticsSettingsScreenViewModelTests: XCTestCase {
private var appSettings: AppSettings!
private var viewModel: AnalyticsSettingsScreenViewModelProtocol!
private var context: AnalyticsSettingsScreenViewModelType.Context!
override func setUp() {
AppSettings.resetAllSettings()
}
override func tearDown() {
AppSettings.resetAllSettings()
}
@MainActor override func setUpWithError() throws {
AppSettings.resetAllSettings()
appSettings = AppSettings()
let analyticsClient = AnalyticsClientMock()
analyticsClient.isRunning = false
ServiceLocator.shared.register(analytics: AnalyticsService(client: analyticsClient,
appSettings: appSettings))
viewModel = AnalyticsSettingsScreenViewModel(appSettings: appSettings,
analytics: ServiceLocator.shared.analytics)
context = viewModel.context
}
func testInitialState() {
XCTAssertFalse(context.enableAnalytics)
}
func testOptIn() {
appSettings.analyticsConsentState = .optedOut
context.send(viewAction: .toggleAnalytics)
XCTAssertTrue(context.enableAnalytics)
}
func testOptOut() {
appSettings.analyticsConsentState = .optedIn
context.send(viewAction: .toggleAnalytics)
XCTAssertFalse(context.enableAnalytics)
}
}