mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Show internet connection warning when uploading keys on log out. (#4027)
* Show the key upload progress when waiting to log out. Add some basic view model tests too. * Show a network suggestion if key upload doesn't report any progress during logout.
This commit is contained in:
@@ -5,9 +5,67 @@
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import XCTest
|
||||
|
||||
@testable import ElementX
|
||||
|
||||
@MainActor
|
||||
class SecureBackupLogoutConfirmationScreenViewModelTests: XCTestCase { }
|
||||
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.$viewState) { $0.mode == .waitingToStart(hasStalled: false) }
|
||||
context.send(viewAction: .logout)
|
||||
try await deferredWaiting.fulfill()
|
||||
|
||||
// Wait for the 2-second timeout.
|
||||
let deferredHasStalled = deferFulfillment(context.$viewState) { $0.mode == .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.$viewState) { $0.mode == .offline }
|
||||
reachabilitySubject.send(.unreachable)
|
||||
try await deferred.fulfill()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user