mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Initial implementation for AppLockSetupFlowCoordinator. (#1949)
Rename AppLockSettingsScreen to AppLockSetupSettingsScreen. Implement forced logout and persist PIN entry attempts.
This commit is contained in:
@@ -20,6 +20,7 @@ import XCTest
|
||||
|
||||
@MainActor
|
||||
class AppLockScreenViewModelTests: XCTestCase {
|
||||
var appSettings: AppSettings!
|
||||
var appLockService: AppLockService!
|
||||
var keychainController: KeychainControllerMock!
|
||||
var viewModel: AppLockScreenViewModelProtocol!
|
||||
@@ -28,8 +29,9 @@ class AppLockScreenViewModelTests: XCTestCase {
|
||||
|
||||
override func setUp() {
|
||||
AppSettings.reset()
|
||||
appSettings = AppSettings()
|
||||
keychainController = KeychainControllerMock()
|
||||
appLockService = AppLockService(keychainController: keychainController, appSettings: AppSettings())
|
||||
appLockService = AppLockService(keychainController: keychainController, appSettings: appSettings)
|
||||
viewModel = AppLockScreenViewModel(appLockService: appLockService)
|
||||
}
|
||||
|
||||
@@ -51,4 +53,60 @@ class AppLockScreenViewModelTests: XCTestCase {
|
||||
// The app should become unlocked.
|
||||
XCTAssertEqual(result, .appUnlocked)
|
||||
}
|
||||
|
||||
func testForgotPIN() {
|
||||
// Given a fresh launch of the app.
|
||||
XCTAssertNil(context.alertInfo, "No alert should be shown initially.")
|
||||
|
||||
// When the user has forgotten their PIN.
|
||||
context.send(viewAction: .forgotPIN)
|
||||
|
||||
// Then an alert should be shown before logging out.
|
||||
XCTAssertEqual(context.alertInfo?.id, .confirmResetPIN, "An alert should be shown before logging out.")
|
||||
}
|
||||
|
||||
func testUnlockFailure() async throws {
|
||||
// Given an invalid PIN code.
|
||||
let pinCode = "2024"
|
||||
keychainController.pinCodeReturnValue = "2023"
|
||||
XCTAssertEqual(context.viewState.numberOfPINAttempts, 0, "The shouldn't be any attempts yet.")
|
||||
XCTAssertFalse(context.viewState.isSubtitleWarning, "No warning should be shown yet.")
|
||||
XCTAssertNil(context.alertInfo, "No alert should be shown yet.")
|
||||
|
||||
// When entering it on the lock screen.
|
||||
viewModel.context.pinCode = pinCode
|
||||
context.send(viewAction: .submitPINCode)
|
||||
|
||||
// Then a failed attempt should be shown.
|
||||
XCTAssertEqual(context.viewState.numberOfPINAttempts, 1, "A failed attempt should have been recorded.")
|
||||
XCTAssertTrue(context.viewState.isSubtitleWarning, "A warning should now be shown.")
|
||||
XCTAssertNil(context.alertInfo, "No alert should be shown yet.")
|
||||
|
||||
// When entering twice more
|
||||
context.send(viewAction: .submitPINCode)
|
||||
context.send(viewAction: .submitPINCode)
|
||||
|
||||
// Then an alert should be shown
|
||||
XCTAssertEqual(context.viewState.numberOfPINAttempts, 3, "All the attempts should have been recorded.")
|
||||
XCTAssertTrue(context.viewState.isSubtitleWarning, "The warning should still be shown.")
|
||||
XCTAssertEqual(context.alertInfo?.id, .forcedLogout, "An alert should now be shown.")
|
||||
}
|
||||
|
||||
func testForceQuitRequiresLogout() {
|
||||
// Given an app with a PIN set where the user attempted to unlock 3 times.
|
||||
keychainController.pinCodeReturnValue = "2023"
|
||||
appSettings.appLockNumberOfPINAttempts = 2
|
||||
XCTAssertNil(context.alertInfo)
|
||||
viewModel.context.pinCode = "0000"
|
||||
context.send(viewAction: .submitPINCode)
|
||||
XCTAssertEqual(appSettings.appLockNumberOfPINAttempts, 3, "The app should have 3 failed attempts before the force quit.")
|
||||
XCTAssertEqual(context.alertInfo?.id, .forcedLogout, "The app should be showing the alert before the force quit.")
|
||||
|
||||
// When force quitting the app and relaunching.
|
||||
viewModel = nil
|
||||
let freshViewModel = AppLockScreenViewModel(appLockService: appLockService)
|
||||
|
||||
// Then the alert should remain in place
|
||||
XCTAssertEqual(freshViewModel.context.alertInfo?.id, .forcedLogout, "The new view model from the fresh launch should also show the alert")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user