BWA-119 - Unable to Access Manual Code Entry After Denying Camera Permissions on (#4891)

This commit is contained in:
Phil Cappelli
2025-03-18 11:50:51 -04:00
committed by GitHub
parent 4f09f5dae4
commit f22156389b
2 changed files with 37 additions and 23 deletions

View File

@@ -31,10 +31,7 @@ import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
@@ -100,12 +97,11 @@ fun ItemListingScreen(
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
val context = LocalContext.current
var shouldShowPermissionDialog by rememberSaveable { mutableStateOf(false) }
val launcher = permissionsManager.getLauncher { isGranted ->
if (isGranted) {
viewModel.trySendAction(ItemListingAction.ScanQrCodeClick)
} else {
shouldShowPermissionDialog = true
viewModel.trySendAction(ItemListingAction.EnterSetupKeyClick)
}
}
val snackbarHostState = remember { SnackbarHostState() }
@@ -151,20 +147,6 @@ fun ItemListingScreen(
}
}
if (shouldShowPermissionDialog) {
BitwardenTwoButtonDialog(
message = stringResource(id = R.string.enable_camera_permission_to_use_the_scanner),
confirmButtonText = stringResource(id = R.string.settings),
dismissButtonText = stringResource(id = R.string.no_thanks),
onConfirmClick = remember(viewModel) {
{ viewModel.trySendAction(ItemListingAction.SettingsClick) }
},
onDismissClick = { shouldShowPermissionDialog = false },
onDismissRequest = { shouldShowPermissionDialog = false },
title = null,
)
}
ItemListingDialogs(
dialog = state.dialog,
onDismissRequest = remember(viewModel) {
@@ -258,7 +240,7 @@ fun ItemListingScreen(
launcher.launch(Manifest.permission.CAMERA)
}
},
onScanQuCodeClick = remember(viewModel) {
onScanQrCodeClick = remember(viewModel) {
{
launcher.launch(Manifest.permission.CAMERA)
}
@@ -580,7 +562,7 @@ fun EmptyItemListingContent(
rememberTopAppBarState(),
),
onAddCodeClick: () -> Unit,
onScanQuCodeClick: () -> Unit,
onScanQrCodeClick: () -> Unit,
onEnterSetupKeyClick: () -> Unit,
onDownloadBitwardenClick: () -> Unit,
onDismissDownloadBitwardenClick: () -> Unit,
@@ -613,7 +595,7 @@ fun EmptyItemListingContent(
contentDescription = stringResource(id = R.string.scan_a_qr_code),
testTag = "ScanQRCodeButton",
),
onScanQrCodeClick = onScanQuCodeClick,
onScanQrCodeClick = onScanQrCodeClick,
),
ItemListingExpandableFabAction.EnterSetupKey(
label = R.string.enter_key_manually.asText(),
@@ -783,7 +765,7 @@ private fun EmptyListingContentPreview() {
modifier = Modifier.padding(horizontal = 16.dp),
appTheme = AppTheme.DEFAULT,
onAddCodeClick = { },
onScanQuCodeClick = { },
onScanQrCodeClick = { },
onEnterSetupKeyClick = { },
actionCardState = ItemListingState.ActionCardState.DownloadBitwardenApp,
onDownloadBitwardenClick = { },

View File

@@ -63,6 +63,38 @@ class ItemListingScreenTest : BaseComposeTest() {
}
}
@Test
@Suppress("MaxLineLength")
fun `when denying camera permissions and attempting to add a code we should be shown the manual entry screen`() {
permissionsManager.getPermissionsResult = false
composeTestRule
.onNodeWithText("Add code")
.performClick()
verify {
viewModel.trySendAction(
ItemListingAction.EnterSetupKeyClick,
)
}
}
@Test
@Suppress("MaxLineLength")
fun `when allowing camera permissions and attempting to add a code we should be shown the scan QR code screen`() {
permissionsManager.getPermissionsResult = true
composeTestRule
.onNodeWithText("Add code")
.performClick()
verify {
viewModel.trySendAction(
ItemListingAction.ScanQrCodeClick,
)
}
}
@Test
@Suppress("MaxLineLength")
fun `shared accounts error message should show when view is Content with SharedCodesDisplayState Error`() {