Files
letro-ios/UnitTests/Sources/SecureBackupLogoutConfirmationScreenViewModelTests.swift
Doug b4174aed22 Adopt StateStoreViewModelV2 in the remaining settings screens. (#4158)
* Move the AuthenticationStartScreen into the Authentication directory.

* Commit the updated Sentry license.

No idea why they dropped the 2024 🤷‍♂️

* Use StateStoreViewModelV2 in BugReportScreen.

* Use StateStoreViewModelV2 in UserDetailsEditScreen.

* Use StateStoreViewModelV2 in NotificationSettingsScreen.

* Use StateStoreViewModelV2 in NotificationSettingsEditScreen.

* Use StateStoreViewModelV2 in LegalInformationScreen.

* Use StateStoreViewModelV2 in LogViewerScreen.

* Use StateStoreViewModelV2 in AnalyticsSettingsScreen.

* Rename AdvancedSettingsScreen directory.

* Use StateStoreViewModelV2 in EncryptionResetScreen.

* Use StateStoreViewModelV2 in EncryptionResetPasswordScreen.

* Use StateStoreViewModelV2 in SecureBackup…Screens.

* Use StateStoreViewModelV2 in LoginScreen.

Seems this one was ignored waiting on the fulfillment transitionValues implementation.

* Use StateStoreViewModelV2 in DeactivateAccountScreen.

* Move DeactivateAccountScreen into the Settings directory.
2025-05-30 12:24:56 +01:00

72 lines
3.0 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 Combine
import XCTest
@testable import ElementX
@MainActor
class SecureBackupLogoutConfirmationScreenViewModelTests: XCTestCase {
var viewModel: SecureBackupLogoutConfirmationScreenViewModel!
var context: SecureBackupLogoutConfirmationScreenViewModel.Context { viewModel.context }
var secureBackupController: SecureBackupControllerMock!
var reachabilitySubject: CurrentValueSubject<NetworkMonitorReachability, Never>!
override func setUp() {
secureBackupController = SecureBackupControllerMock()
secureBackupController.underlyingKeyBackupState = CurrentValueSubject<SecureBackupKeyBackupState, Never>(.enabled).asCurrentValuePublisher()
reachabilitySubject = CurrentValueSubject<NetworkMonitorReachability, Never>(.reachable)
let networkMonitor = NetworkMonitorMock()
networkMonitor.underlyingReachabilityPublisher = reachabilitySubject.asCurrentValuePublisher()
let appMediator = AppMediatorMock()
appMediator.underlyingNetworkMonitor = networkMonitor
viewModel = SecureBackupLogoutConfirmationScreenViewModel(secureBackupController: secureBackupController,
appMediator: appMediator)
}
func testInitialState() {
XCTAssertEqual(context.viewState.mode, .saveRecoveryKey)
}
func testOngoingState() async throws {
testInitialState()
let progressExpectation = expectation(description: "The upload progress callback should be called.")
secureBackupController.waitForKeyBackupUploadUploadStateSubjectClosure = { stateSubject in
try? await Task.sleep(for: .seconds(4))
stateSubject.send(.uploading(uploadedKeyCount: 50, totalKeyCount: 100))
progressExpectation.fulfill()
return .success(())
}
let deferredWaiting = deferFulfillment(context.observe(\.viewState.mode)) { $0 == .waitingToStart(hasStalled: false) }
context.send(viewAction: .logout)
try await deferredWaiting.fulfill()
// Wait for the 2-second timeout.
let deferredHasStalled = deferFulfillment(context.observe(\.viewState.mode)) { $0 == .waitingToStart(hasStalled: true) }
try await deferredHasStalled.fulfill()
// Wait for the progress to be reported.
await fulfillment(of: [progressExpectation])
XCTAssertEqual(context.viewState.mode, .backupOngoing(progress: 0.5))
}
func testOfflineState() async throws {
try await testOngoingState()
let deferred = deferFulfillment(context.observe(\.viewState.mode)) { $0 == .offline }
reachabilitySubject.send(.unreachable)
try await deferred.fulfill()
}
}