Pin: add tests and make LockScreenConfig an injectable data class
This commit is contained in:
parent
b135670196
commit
a34604512d
15 changed files with 203 additions and 36 deletions
|
|
@ -201,6 +201,7 @@ dependencies {
|
||||||
implementation(projects.features.call)
|
implementation(projects.features.call)
|
||||||
implementation(projects.anvilannotations)
|
implementation(projects.anvilannotations)
|
||||||
implementation(projects.appnav)
|
implementation(projects.appnav)
|
||||||
|
implementation(projects.appconfig)
|
||||||
anvil(projects.anvilcodegen)
|
anvil(projects.anvilcodegen)
|
||||||
|
|
||||||
implementation(libs.appyx.core)
|
implementation(libs.appyx.core)
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,20 @@
|
||||||
plugins {
|
plugins {
|
||||||
id("java-library")
|
id("java-library")
|
||||||
alias(libs.plugins.kotlin.jvm)
|
alias(libs.plugins.kotlin.jvm)
|
||||||
|
alias(libs.plugins.anvil)
|
||||||
|
alias(libs.plugins.ksp)
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
|
anvil {
|
||||||
|
generateDaggerFactories.set(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(libs.dagger)
|
||||||
|
implementation(projects.libraries.di)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,30 +16,52 @@
|
||||||
|
|
||||||
package io.element.android.appconfig
|
package io.element.android.appconfig
|
||||||
|
|
||||||
object LockScreenConfig {
|
import com.squareup.anvil.annotations.ContributesTo
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.Provides
|
||||||
|
import io.element.android.libraries.di.AppScope
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for the lock screen feature.
|
||||||
|
*/
|
||||||
|
data class LockScreenConfig(
|
||||||
/**
|
/**
|
||||||
* Whether the PIN is mandatory or not.
|
* Whether the PIN is mandatory or not.
|
||||||
*/
|
*/
|
||||||
const val IS_PIN_MANDATORY: Boolean = false
|
val isPinMandatory: Boolean,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some PINs are blacklisted.
|
* Some PINs are blacklisted.
|
||||||
*/
|
*/
|
||||||
val PIN_BLACKLIST = setOf("0000", "1234")
|
val pinBlacklist: Set<String>,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The size of the PIN.
|
* The size of the PIN.
|
||||||
*/
|
*/
|
||||||
const val PIN_SIZE = 4
|
val pinSize: Int,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of attempts before the user is logged out.
|
* Number of attempts before the user is logged out.
|
||||||
*/
|
*/
|
||||||
const val MAX_PIN_CODE_ATTEMPTS_NUMBER_BEFORE_LOGOUT = 3
|
val maxPinCodeAttemptsBeforeLogout: Int,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Time period before locking the app once backgrounded.
|
* Time period before locking the app once backgrounded.
|
||||||
*/
|
*/
|
||||||
const val GRACE_PERIOD_IN_MILLIS = 90 * 1000L
|
val gracePeriodInMillis: Long
|
||||||
|
)
|
||||||
|
|
||||||
|
@ContributesTo(AppScope::class)
|
||||||
|
@Module
|
||||||
|
object LockScreenConfigModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesLockScreenConfig(): LockScreenConfig = LockScreenConfig(
|
||||||
|
isPinMandatory = false,
|
||||||
|
pinBlacklist = setOf("0000", "1234"),
|
||||||
|
pinSize = 4,
|
||||||
|
maxPinCodeAttemptsBeforeLogout = 3,
|
||||||
|
gracePeriodInMillis = 90_000L
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import javax.inject.Inject
|
||||||
@SingleIn(AppScope::class)
|
@SingleIn(AppScope::class)
|
||||||
@ContributesBinding(AppScope::class)
|
@ContributesBinding(AppScope::class)
|
||||||
class DefaultLockScreenService @Inject constructor(
|
class DefaultLockScreenService @Inject constructor(
|
||||||
|
private val lockScreenConfig: LockScreenConfig,
|
||||||
private val featureFlagService: FeatureFlagService,
|
private val featureFlagService: FeatureFlagService,
|
||||||
private val pinCodeManager: PinCodeManager,
|
private val pinCodeManager: PinCodeManager,
|
||||||
private val coroutineScope: CoroutineScope,
|
private val coroutineScope: CoroutineScope,
|
||||||
|
|
@ -91,14 +92,14 @@ class DefaultLockScreenService @Inject constructor(
|
||||||
if (isInForeground) {
|
if (isInForeground) {
|
||||||
lockJob?.cancel()
|
lockJob?.cancel()
|
||||||
} else {
|
} else {
|
||||||
lockJob = lockIfNeeded(delayInMillis = LockScreenConfig.GRACE_PERIOD_IN_MILLIS)
|
lockJob = lockIfNeeded(delayInMillis = lockScreenConfig.gracePeriodInMillis)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun isSetupRequired(): Boolean {
|
override suspend fun isSetupRequired(): Boolean {
|
||||||
return LockScreenConfig.IS_PIN_MANDATORY
|
return lockScreenConfig.isPinMandatory
|
||||||
&& featureFlagService.isFeatureEnabled(FeatureFlags.PinUnlock)
|
&& featureFlagService.isFeatureEnabled(FeatureFlags.PinUnlock)
|
||||||
&& !pinCodeManager.isPinCodeAvailable()
|
&& !pinCodeManager.isPinCodeAvailable()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(na
|
||||||
@ContributesBinding(AppScope::class)
|
@ContributesBinding(AppScope::class)
|
||||||
class PreferencesPinCodeStore @Inject constructor(
|
class PreferencesPinCodeStore @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
|
private val lockScreenConfig: LockScreenConfig,
|
||||||
) : PinCodeStore {
|
) : PinCodeStore {
|
||||||
|
|
||||||
private val pinCodeKey = stringPreferencesKey("encoded_pin_code")
|
private val pinCodeKey = stringPreferencesKey("encoded_pin_code")
|
||||||
|
|
@ -59,7 +60,7 @@ class PreferencesPinCodeStore @Inject constructor(
|
||||||
|
|
||||||
override suspend fun resetCounter() {
|
override suspend fun resetCounter() {
|
||||||
context.dataStore.edit { preferences ->
|
context.dataStore.edit { preferences ->
|
||||||
preferences[remainingAttemptsKey] = LockScreenConfig.MAX_PIN_CODE_ATTEMPTS_NUMBER_BEFORE_LOGOUT
|
preferences[remainingAttemptsKey] = lockScreenConfig.maxPinCodeAttemptsBeforeLogout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,5 +88,5 @@ class PreferencesPinCodeStore @Inject constructor(
|
||||||
}.first()
|
}.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Preferences.getRemainingPinCodeAttemptsNumber() = this[remainingAttemptsKey] ?: LockScreenConfig.MAX_PIN_CODE_ATTEMPTS_NUMBER_BEFORE_LOGOUT
|
private fun Preferences.getRemainingPinCodeAttemptsNumber() = this[remainingAttemptsKey] ?: lockScreenConfig.maxPinCodeAttemptsBeforeLogout
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
package io.element.android.features.lockscreen.impl.settings
|
package io.element.android.features.lockscreen.impl.settings
|
||||||
|
|
||||||
sealed interface LockScreenSettingsEvents {
|
sealed interface LockScreenSettingsEvents {
|
||||||
data object RemovePin : LockScreenSettingsEvents
|
data object OnRemovePin : LockScreenSettingsEvents
|
||||||
data object ConfirmRemovePin : LockScreenSettingsEvents
|
data object ConfirmRemovePin : LockScreenSettingsEvents
|
||||||
data object CancelRemovePin : LockScreenSettingsEvents
|
data object CancelRemovePin : LockScreenSettingsEvents
|
||||||
data object ToggleBiometric : LockScreenSettingsEvents
|
data object ToggleBiometric : LockScreenSettingsEvents
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class LockScreenSettingsPresenter @Inject constructor(
|
class LockScreenSettingsPresenter @Inject constructor(
|
||||||
|
private val lockScreenConfig: LockScreenConfig,
|
||||||
private val pinCodeManager: PinCodeManager,
|
private val pinCodeManager: PinCodeManager,
|
||||||
private val coroutineScope: CoroutineScope,
|
private val coroutineScope: CoroutineScope,
|
||||||
) : Presenter<LockScreenSettingsState> {
|
) : Presenter<LockScreenSettingsState> {
|
||||||
|
|
@ -50,7 +51,7 @@ class LockScreenSettingsPresenter @Inject constructor(
|
||||||
mutableStateOf(false)
|
mutableStateOf(false)
|
||||||
}
|
}
|
||||||
LaunchedEffect(triggerComputation) {
|
LaunchedEffect(triggerComputation) {
|
||||||
showRemovePinOption = !LockScreenConfig.IS_PIN_MANDATORY && pinCodeManager.isPinCodeAvailable()
|
showRemovePinOption = !lockScreenConfig.isPinMandatory && pinCodeManager.isPinCodeAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleEvents(event: LockScreenSettingsEvents) {
|
fun handleEvents(event: LockScreenSettingsEvents) {
|
||||||
|
|
@ -58,12 +59,14 @@ class LockScreenSettingsPresenter @Inject constructor(
|
||||||
LockScreenSettingsEvents.CancelRemovePin -> showRemovePinConfirmation = false
|
LockScreenSettingsEvents.CancelRemovePin -> showRemovePinConfirmation = false
|
||||||
LockScreenSettingsEvents.ConfirmRemovePin -> {
|
LockScreenSettingsEvents.ConfirmRemovePin -> {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
showRemovePinConfirmation = false
|
if (showRemovePinConfirmation) {
|
||||||
pinCodeManager.deletePinCode()
|
showRemovePinConfirmation = false
|
||||||
triggerComputation++
|
pinCodeManager.deletePinCode()
|
||||||
|
triggerComputation++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LockScreenSettingsEvents.RemovePin -> showRemovePinConfirmation = true
|
LockScreenSettingsEvents.OnRemovePin -> showRemovePinConfirmation = true
|
||||||
LockScreenSettingsEvents.ToggleBiometric -> {
|
LockScreenSettingsEvents.ToggleBiometric -> {
|
||||||
//TODO branch biometric logic
|
//TODO branch biometric logic
|
||||||
}
|
}
|
||||||
|
|
@ -77,5 +80,4 @@ class LockScreenSettingsPresenter @Inject constructor(
|
||||||
eventSink = ::handleEvents
|
eventSink = ::handleEvents
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ fun LockScreenSettingsView(
|
||||||
title = stringResource(id = R.string.screen_app_lock_settings_remove_pin),
|
title = stringResource(id = R.string.screen_app_lock_settings_remove_pin),
|
||||||
tintColor = ElementTheme.colors.textCriticalPrimary,
|
tintColor = ElementTheme.colors.textCriticalPrimary,
|
||||||
onClick = {
|
onClick = {
|
||||||
state.eventSink(LockScreenSettingsEvents.RemovePin)
|
state.eventSink(LockScreenSettingsEvents.OnRemovePin)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import kotlinx.coroutines.delay
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SetupPinPresenter @Inject constructor(
|
class SetupPinPresenter @Inject constructor(
|
||||||
|
private val lockScreenConfig: LockScreenConfig,
|
||||||
private val pinValidator: PinValidator,
|
private val pinValidator: PinValidator,
|
||||||
private val buildMeta: BuildMeta,
|
private val buildMeta: BuildMeta,
|
||||||
private val pinCodeManager: PinCodeManager,
|
private val pinCodeManager: PinCodeManager,
|
||||||
|
|
@ -41,10 +42,10 @@ class SetupPinPresenter @Inject constructor(
|
||||||
@Composable
|
@Composable
|
||||||
override fun present(): SetupPinState {
|
override fun present(): SetupPinState {
|
||||||
var choosePinEntry by remember {
|
var choosePinEntry by remember {
|
||||||
mutableStateOf(PinEntry.createEmpty(LockScreenConfig.PIN_SIZE))
|
mutableStateOf(PinEntry.createEmpty(lockScreenConfig.pinSize))
|
||||||
}
|
}
|
||||||
var confirmPinEntry by remember {
|
var confirmPinEntry by remember {
|
||||||
mutableStateOf(PinEntry.createEmpty(LockScreenConfig.PIN_SIZE))
|
mutableStateOf(PinEntry.createEmpty(lockScreenConfig.pinSize))
|
||||||
}
|
}
|
||||||
var isConfirmationStep by remember {
|
var isConfirmationStep by remember {
|
||||||
mutableStateOf(false)
|
mutableStateOf(false)
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,7 @@ import io.element.android.appconfig.LockScreenConfig
|
||||||
import io.element.android.features.lockscreen.impl.pin.model.PinEntry
|
import io.element.android.features.lockscreen.impl.pin.model.PinEntry
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class PinValidator internal constructor(private val pinBlacklist: Set<String>) {
|
class PinValidator @Inject constructor(private val lockScreenConfig: LockScreenConfig) {
|
||||||
|
|
||||||
@Inject
|
|
||||||
constructor() : this(LockScreenConfig.PIN_BLACKLIST)
|
|
||||||
|
|
||||||
sealed interface Result {
|
sealed interface Result {
|
||||||
data object Valid : Result
|
data object Valid : Result
|
||||||
|
|
@ -32,7 +29,7 @@ class PinValidator internal constructor(private val pinBlacklist: Set<String>) {
|
||||||
|
|
||||||
fun isPinValid(pinEntry: PinEntry): Result {
|
fun isPinValid(pinEntry: PinEntry): Result {
|
||||||
val pinAsText = pinEntry.toText()
|
val pinAsText = pinEntry.toText()
|
||||||
val isBlacklisted = pinBlacklist.any { it == pinAsText }
|
val isBlacklisted = lockScreenConfig.pinBlacklist.any { it == pinAsText }
|
||||||
return if (isBlacklisted) {
|
return if (isBlacklisted) {
|
||||||
Result.Invalid(SetupPinFailure.PinBlacklisted)
|
Result.Invalid(SetupPinFailure.PinBlacklisted)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.lockscreen.impl.fixtures
|
||||||
|
|
||||||
|
import io.element.android.appconfig.LockScreenConfig
|
||||||
|
|
||||||
|
internal fun aLockScreenConfig(
|
||||||
|
isPinMandatory: Boolean = false,
|
||||||
|
pinBlacklist: Set<String> = emptySet(),
|
||||||
|
pinSize: Int = 4,
|
||||||
|
maxPinCodeAttemptsBeforeLogout: Int = 3,
|
||||||
|
gracePeriodInMillis: Long = 5 * 60 * 1000L
|
||||||
|
): LockScreenConfig {
|
||||||
|
return LockScreenConfig(
|
||||||
|
isPinMandatory = isPinMandatory,
|
||||||
|
pinBlacklist = pinBlacklist,
|
||||||
|
pinSize = pinSize,
|
||||||
|
maxPinCodeAttemptsBeforeLogout = maxPinCodeAttemptsBeforeLogout,
|
||||||
|
gracePeriodInMillis = gracePeriodInMillis
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -14,15 +14,20 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.element.android.features.lockscreen.impl.pin
|
package io.element.android.features.lockscreen.impl.fixtures
|
||||||
|
|
||||||
|
import io.element.android.features.lockscreen.impl.pin.DefaultPinCodeManager
|
||||||
|
import io.element.android.features.lockscreen.impl.pin.PinCodeManager
|
||||||
import io.element.android.features.lockscreen.impl.pin.storage.InMemoryPinCodeStore
|
import io.element.android.features.lockscreen.impl.pin.storage.InMemoryPinCodeStore
|
||||||
|
import io.element.android.features.lockscreen.impl.pin.storage.PinCodeStore
|
||||||
|
import io.element.android.libraries.cryptography.api.EncryptionDecryptionService
|
||||||
import io.element.android.libraries.cryptography.impl.AESEncryptionDecryptionService
|
import io.element.android.libraries.cryptography.impl.AESEncryptionDecryptionService
|
||||||
import io.element.android.libraries.cryptography.test.SimpleSecretKeyProvider
|
import io.element.android.libraries.cryptography.test.SimpleSecretKeyProvider
|
||||||
|
|
||||||
internal fun createPinCodeManager(): PinCodeManager {
|
internal fun aPinCodeManager(
|
||||||
val pinCodeStore = InMemoryPinCodeStore()
|
pinCodeStore: PinCodeStore = InMemoryPinCodeStore(),
|
||||||
val secretKeyProvider = SimpleSecretKeyProvider()
|
secretKeyProvider: SimpleSecretKeyProvider = SimpleSecretKeyProvider(),
|
||||||
val encryptionDecryptionService = AESEncryptionDecryptionService()
|
encryptionDecryptionService: EncryptionDecryptionService = AESEncryptionDecryptionService(),
|
||||||
|
): PinCodeManager {
|
||||||
return DefaultPinCodeManager(secretKeyProvider, encryptionDecryptionService, pinCodeStore)
|
return DefaultPinCodeManager(secretKeyProvider, encryptionDecryptionService, pinCodeStore)
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.lockscreen.impl.settings
|
||||||
|
|
||||||
|
import app.cash.molecule.RecompositionMode
|
||||||
|
import app.cash.molecule.moleculeFlow
|
||||||
|
import app.cash.turbine.test
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.appconfig.LockScreenConfig
|
||||||
|
import io.element.android.features.lockscreen.impl.fixtures.aLockScreenConfig
|
||||||
|
import io.element.android.features.lockscreen.impl.fixtures.aPinCodeManager
|
||||||
|
import io.element.android.tests.testutils.awaitLastSequentialItem
|
||||||
|
import io.element.android.tests.testutils.consumeItemsUntilPredicate
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class LockScreenSettingsPresenterTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `present - remove pin flow`() = runTest {
|
||||||
|
val presenter = createLockScreenSettingsPresenter(this)
|
||||||
|
moleculeFlow(RecompositionMode.Immediate) {
|
||||||
|
presenter.present()
|
||||||
|
}.test {
|
||||||
|
consumeItemsUntilPredicate { state ->
|
||||||
|
state.showRemovePinOption
|
||||||
|
}.last().also { state ->
|
||||||
|
state.eventSink(LockScreenSettingsEvents.OnRemovePin)
|
||||||
|
}
|
||||||
|
awaitLastSequentialItem().also { state ->
|
||||||
|
assertThat(state.showRemovePinConfirmation).isTrue()
|
||||||
|
state.eventSink(LockScreenSettingsEvents.CancelRemovePin)
|
||||||
|
}
|
||||||
|
awaitLastSequentialItem().also { state ->
|
||||||
|
assertThat(state.showRemovePinConfirmation).isFalse()
|
||||||
|
state.eventSink(LockScreenSettingsEvents.OnRemovePin)
|
||||||
|
}
|
||||||
|
awaitLastSequentialItem().also { state ->
|
||||||
|
assertThat(state.showRemovePinConfirmation).isTrue()
|
||||||
|
state.eventSink(LockScreenSettingsEvents.ConfirmRemovePin)
|
||||||
|
}
|
||||||
|
consumeItemsUntilPredicate {
|
||||||
|
it.showRemovePinOption.not()
|
||||||
|
}.last().also { state ->
|
||||||
|
assertThat(state.showRemovePinConfirmation).isFalse()
|
||||||
|
assertThat(state.showRemovePinOption).isFalse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun createLockScreenSettingsPresenter(
|
||||||
|
coroutineScope: CoroutineScope,
|
||||||
|
lockScreenConfig: LockScreenConfig = aLockScreenConfig(),
|
||||||
|
): LockScreenSettingsPresenter {
|
||||||
|
val pinCodeManager = aPinCodeManager().apply {
|
||||||
|
createPinCode("1234")
|
||||||
|
}
|
||||||
|
return LockScreenSettingsPresenter(
|
||||||
|
pinCodeManager = pinCodeManager,
|
||||||
|
coroutineScope = coroutineScope,
|
||||||
|
lockScreenConfig = lockScreenConfig,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,8 +20,10 @@ import app.cash.molecule.RecompositionMode
|
||||||
import app.cash.molecule.moleculeFlow
|
import app.cash.molecule.moleculeFlow
|
||||||
import app.cash.turbine.test
|
import app.cash.turbine.test
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.appconfig.LockScreenConfig
|
||||||
|
import io.element.android.features.lockscreen.impl.fixtures.aLockScreenConfig
|
||||||
|
import io.element.android.features.lockscreen.impl.fixtures.aPinCodeManager
|
||||||
import io.element.android.features.lockscreen.impl.pin.PinCodeManager
|
import io.element.android.features.lockscreen.impl.pin.PinCodeManager
|
||||||
import io.element.android.features.lockscreen.impl.pin.createPinCodeManager
|
|
||||||
import io.element.android.features.lockscreen.impl.pin.model.assertEmpty
|
import io.element.android.features.lockscreen.impl.pin.model.assertEmpty
|
||||||
import io.element.android.features.lockscreen.impl.pin.model.assertText
|
import io.element.android.features.lockscreen.impl.pin.model.assertText
|
||||||
import io.element.android.features.lockscreen.impl.setup.validation.PinValidator
|
import io.element.android.features.lockscreen.impl.setup.validation.PinValidator
|
||||||
|
|
@ -108,9 +110,19 @@ class SetupPinPresenterTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createSetupPinPresenter(callback: PinCodeManager.Callback): SetupPinPresenter {
|
private fun createSetupPinPresenter(
|
||||||
val pinCodeManager = createPinCodeManager()
|
callback: PinCodeManager.Callback,
|
||||||
|
lockScreenConfig: LockScreenConfig = aLockScreenConfig(
|
||||||
|
pinBlacklist = setOf(blacklistedPin)
|
||||||
|
),
|
||||||
|
): SetupPinPresenter {
|
||||||
|
val pinCodeManager = aPinCodeManager()
|
||||||
pinCodeManager.addCallback(callback)
|
pinCodeManager.addCallback(callback)
|
||||||
return SetupPinPresenter(PinValidator(setOf(blacklistedPin)), aBuildMeta(), pinCodeManager)
|
return SetupPinPresenter(
|
||||||
|
lockScreenConfig = lockScreenConfig,
|
||||||
|
pinValidator = PinValidator(lockScreenConfig),
|
||||||
|
buildMeta = aBuildMeta(),
|
||||||
|
pinCodeManager = pinCodeManager
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import app.cash.molecule.moleculeFlow
|
||||||
import app.cash.turbine.test
|
import app.cash.turbine.test
|
||||||
import com.google.common.truth.Truth.assertThat
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.element.android.features.lockscreen.impl.pin.PinCodeManager
|
import io.element.android.features.lockscreen.impl.pin.PinCodeManager
|
||||||
import io.element.android.features.lockscreen.impl.pin.createPinCodeManager
|
import io.element.android.features.lockscreen.impl.fixtures.aPinCodeManager
|
||||||
import io.element.android.features.lockscreen.impl.pin.model.PinEntry
|
import io.element.android.features.lockscreen.impl.pin.model.PinEntry
|
||||||
import io.element.android.features.lockscreen.impl.pin.model.assertText
|
import io.element.android.features.lockscreen.impl.pin.model.assertText
|
||||||
import io.element.android.features.lockscreen.impl.unlock.keypad.PinKeypadModel
|
import io.element.android.features.lockscreen.impl.unlock.keypad.PinKeypadModel
|
||||||
|
|
@ -147,7 +147,7 @@ class PinUnlockPresenterTest {
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
callback: PinCodeManager.Callback = object : PinCodeManager.Callback {},
|
callback: PinCodeManager.Callback = object : PinCodeManager.Callback {},
|
||||||
): PinUnlockPresenter {
|
): PinUnlockPresenter {
|
||||||
val pinCodeManager = createPinCodeManager().apply {
|
val pinCodeManager = aPinCodeManager().apply {
|
||||||
addCallback(callback)
|
addCallback(callback)
|
||||||
createPinCode(completePin)
|
createPinCode(completePin)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue