Skip to content

Commit aac2345

Browse files
authored
[PM-18545] Hide section when no unlock option are available (#4751)
1 parent 61c48bf commit aac2345

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/accountsecurity/AccountSecurityScreen.kt

+14-10
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import com.x8bit.bitwarden.ui.platform.components.toggle.BitwardenUnlockWithPinS
6262
import com.x8bit.bitwarden.ui.platform.components.util.rememberVectorPainter
6363
import com.x8bit.bitwarden.ui.platform.composition.LocalBiometricsManager
6464
import com.x8bit.bitwarden.ui.platform.composition.LocalIntentManager
65+
import com.x8bit.bitwarden.ui.platform.manager.biometrics.BiometricSupportStatus
6566
import com.x8bit.bitwarden.ui.platform.manager.biometrics.BiometricsManager
6667
import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager
6768
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
@@ -228,17 +229,20 @@ fun AccountSecurityScreen(
228229
.fillMaxWidth(),
229230
)
230231

231-
Spacer(Modifier.height(16.dp))
232-
BitwardenListHeaderText(
233-
label = stringResource(id = R.string.unlock_options),
234-
modifier = Modifier
235-
.fillMaxWidth()
236-
.standardHorizontalMargin()
237-
.padding(horizontal = 16.dp),
238-
)
239-
Spacer(modifier = Modifier.height(height = 8.dp))
240-
241232
val biometricSupportStatus = biometricsManager.biometricSupportStatus
233+
if (biometricSupportStatus != BiometricSupportStatus.NOT_SUPPORTED ||
234+
!state.removeUnlockWithPinPolicyEnabled ||
235+
state.isUnlockWithPinEnabled) {
236+
Spacer(Modifier.height(16.dp))
237+
BitwardenListHeaderText(
238+
label = stringResource(id = R.string.unlock_options),
239+
modifier = Modifier
240+
.fillMaxWidth()
241+
.standardHorizontalMargin()
242+
.padding(horizontal = 16.dp),
243+
)
244+
Spacer(modifier = Modifier.height(height = 8.dp))
245+
}
242246
BitwardenUnlockWithBiometricsSwitch(
243247
biometricSupportStatus = biometricSupportStatus,
244248
isChecked = state.isUnlockWithBiometricsEnabled || showBiometricsPrompt,

app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/accountsecurity/AccountSecurityScreenTest.kt

+50
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.x8bit.bitwarden.ui.platform.manager.biometrics.BiometricsManager
3030
import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager
3131
import com.x8bit.bitwarden.ui.util.assertNoDialogExists
3232
import com.x8bit.bitwarden.ui.util.assertNoPopupExists
33+
import io.mockk.coEvery
3334
import io.mockk.every
3435
import io.mockk.just
3536
import io.mockk.mockk
@@ -241,6 +242,55 @@ class AccountSecurityScreenTest : BaseComposeTest() {
241242
composeTestRule.onNodeWithText("Unlock with Biometrics").assertIsOn()
242243
}
243244

245+
@Suppress("MaxLineLength")
246+
@Test
247+
fun `unlock option section should be displayed according to state if biometrics is available`() {
248+
val section = "UNLOCK OPTIONS"
249+
composeTestRule.onNodeWithText(section).performScrollTo().assertIsDisplayed()
250+
251+
mutableStateFlow.update {
252+
DEFAULT_STATE.copy(
253+
removeUnlockWithPinPolicyEnabled = true,
254+
isUnlockWithPinEnabled = true,
255+
)
256+
}
257+
composeTestRule.onNodeWithText(section).performScrollTo().assertIsDisplayed()
258+
259+
mutableStateFlow.update {
260+
DEFAULT_STATE.copy(
261+
removeUnlockWithPinPolicyEnabled = true,
262+
isUnlockWithPinEnabled = false,
263+
)
264+
}
265+
composeTestRule.onNodeWithText(section).performScrollTo().assertIsDisplayed()
266+
}
267+
268+
@Suppress("MaxLineLength")
269+
@Test
270+
fun `unlock option section should be displayed according to state if biometrics is not available`() {
271+
coEvery {
272+
biometricsManager.biometricSupportStatus
273+
} returns BiometricSupportStatus.NOT_SUPPORTED
274+
val section = "UNLOCK OPTIONS"
275+
276+
composeTestRule.onNodeWithText(section).performScrollTo().assertIsDisplayed()
277+
mutableStateFlow.update {
278+
DEFAULT_STATE.copy(
279+
removeUnlockWithPinPolicyEnabled = true,
280+
isUnlockWithPinEnabled = true,
281+
)
282+
}
283+
composeTestRule.onNodeWithText(section).performScrollTo().assertIsDisplayed()
284+
285+
mutableStateFlow.update {
286+
DEFAULT_STATE.copy(
287+
removeUnlockWithPinPolicyEnabled = true,
288+
isUnlockWithPinEnabled = false,
289+
)
290+
}
291+
composeTestRule.onNodeWithText(section).assertDoesNotExist()
292+
}
293+
244294
@Test
245295
fun `unlock with pin toggle should be displayed according to state`() {
246296
val toggleText = "Unlock with PIN code"

0 commit comments

Comments
 (0)