|
| 1 | +/* |
| 2 | + * Copyright 2025 New Vector Ltd. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | + * Please see LICENSE files in the repository root for full details. |
| 6 | + */ |
| 7 | + |
| 8 | +package io.element.android.features.lockscreen.impl.unlock |
| 9 | + |
| 10 | +import androidx.biometric.BiometricPrompt |
| 11 | +import com.google.common.truth.Truth.assertThat |
| 12 | +import io.element.android.features.lockscreen.impl.biometric.BiometricAuthenticator |
| 13 | +import io.element.android.features.lockscreen.impl.biometric.BiometricUnlockError |
| 14 | +import io.element.android.libraries.architecture.AsyncData |
| 15 | +import org.junit.Test |
| 16 | + |
| 17 | +class PinUnlockStateTest { |
| 18 | + @Test |
| 19 | + fun `isSignOutPromptCancellable should have expected values`() { |
| 20 | + assertThat(aPinUnlockState(remainingAttempts = AsyncData.Uninitialized).isSignOutPromptCancellable).isTrue() |
| 21 | + assertThat(aPinUnlockState(remainingAttempts = AsyncData.Success(1)).isSignOutPromptCancellable).isTrue() |
| 22 | + assertThat(aPinUnlockState(remainingAttempts = AsyncData.Success(0)).isSignOutPromptCancellable).isFalse() |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + fun `biometricUnlockErrorMessage and showBiometricUnlockError should have expected values`() { |
| 27 | + listOf( |
| 28 | + null, |
| 29 | + BiometricAuthenticator.AuthenticationResult.Failure(), |
| 30 | + BiometricAuthenticator.AuthenticationResult.Success, |
| 31 | + ).forEach { biometricUnlockResult -> |
| 32 | + aPinUnlockState( |
| 33 | + biometricUnlockResult = biometricUnlockResult, |
| 34 | + ).let { |
| 35 | + assertThat(it.biometricUnlockErrorMessage).isNull() |
| 36 | + assertThat(it.showBiometricUnlockError).isFalse() |
| 37 | + } |
| 38 | + } |
| 39 | + listOf( |
| 40 | + BiometricPrompt.ERROR_HW_UNAVAILABLE, |
| 41 | + BiometricPrompt.ERROR_UNABLE_TO_PROCESS, |
| 42 | + BiometricPrompt.ERROR_TIMEOUT, |
| 43 | + BiometricPrompt.ERROR_NO_SPACE, |
| 44 | + BiometricPrompt.ERROR_CANCELED, |
| 45 | + BiometricPrompt.ERROR_VENDOR, |
| 46 | + BiometricPrompt.ERROR_USER_CANCELED, |
| 47 | + BiometricPrompt.ERROR_NO_BIOMETRICS, |
| 48 | + BiometricPrompt.ERROR_HW_NOT_PRESENT, |
| 49 | + BiometricPrompt.ERROR_NEGATIVE_BUTTON, |
| 50 | + BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL, |
| 51 | + BiometricPrompt.ERROR_SECURITY_UPDATE_REQUIRED, |
| 52 | + ).forEach { code -> |
| 53 | + aPinUnlockState( |
| 54 | + biometricUnlockResult = BiometricAuthenticator.AuthenticationResult.Failure( |
| 55 | + error = BiometricUnlockError(code, "Error message") |
| 56 | + ), |
| 57 | + ).let { |
| 58 | + assertThat(it.biometricUnlockErrorMessage).isNull() |
| 59 | + assertThat(it.showBiometricUnlockError).isFalse() |
| 60 | + } |
| 61 | + } |
| 62 | + listOf( |
| 63 | + BiometricPrompt.ERROR_LOCKOUT, |
| 64 | + BiometricPrompt.ERROR_LOCKOUT_PERMANENT, |
| 65 | + ).forEach { code -> |
| 66 | + aPinUnlockState( |
| 67 | + biometricUnlockResult = BiometricAuthenticator.AuthenticationResult.Failure( |
| 68 | + error = BiometricUnlockError(code, "Error message") |
| 69 | + ), |
| 70 | + ).let { |
| 71 | + assertThat(it.biometricUnlockErrorMessage).isEqualTo("Error message") |
| 72 | + assertThat(it.showBiometricUnlockError).isTrue() |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments