diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountScreen.kt index 6178b7499..0d59afd9b 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountScreen.kt @@ -40,6 +40,8 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.CustomAccessibilityAction import androidx.compose.ui.semantics.customActions import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.semantics.toggleableState +import androidx.compose.ui.state.ToggleableState import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.withStyle import androidx.compose.ui.unit.dp @@ -317,6 +319,7 @@ private fun TermsAndPrivacySwitch( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .semantics(mergeDescendants = true) { + toggleableState = ToggleableState(isChecked) customActions = listOf( CustomAccessibilityAction( label = termsString, diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountScreenTest.kt index 79f0d4ac7..33962f0cb 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountScreenTest.kt @@ -4,6 +4,8 @@ import android.content.Intent import android.net.Uri import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsOff +import androidx.compose.ui.test.assertIsOn import androidx.compose.ui.test.filterToOne import androidx.compose.ui.test.hasAnyAncestor import androidx.compose.ui.test.isDialog @@ -96,6 +98,32 @@ class CreateAccountScreenTest : BaseComposeTest() { verify { viewModel.trySendAction(CheckDataBreachesToggle(true)) } } + @Test + fun `accept policies should be toggled on or off according to the state`() { + val mutableStateFlow = MutableStateFlow(DEFAULT_STATE) + val viewModel = mockk(relaxed = true) { + every { stateFlow } returns mutableStateFlow + every { eventFlow } returns emptyFlow() + every { trySendAction(AcceptPoliciesToggle(true)) } returns Unit + } + composeTestRule.setContent { + CreateAccountScreen( + onNavigateBack = {}, + onNavigateToLogin = { _, _ -> }, + viewModel = viewModel, + ) + } + composeTestRule + .onNodeWithText("By activating this switch you agree", substring = true) + .assertIsOff() + + mutableStateFlow.update { it.copy(isAcceptPoliciesToggled = true) } + + composeTestRule + .onNodeWithText("By activating this switch you agree", substring = true) + .assertIsOn() + } + @Test fun `accept policies click should send AcceptPoliciesToggle action`() { val viewModel = mockk(relaxed = true) {