mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-1360: Prompt for push notification permission when approving passwordless logins (#677)
This commit is contained in:
committed by
Álison Fernandes
parent
3c4b823014
commit
a706db2b28
+101
-1
@@ -23,6 +23,7 @@ import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFl
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.manager.intent.IntentManager
|
||||
import com.x8bit.bitwarden.ui.platform.manager.permissions.FakePermissionManager
|
||||
import com.x8bit.bitwarden.ui.util.assertNoDialogExists
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
@@ -43,7 +44,10 @@ class AccountSecurityScreenTest : BaseComposeTest() {
|
||||
|
||||
private val intentManager = mockk<IntentManager> {
|
||||
every { launchUri(any()) } just runs
|
||||
every { startActivity(any()) } just runs
|
||||
every { startApplicationDetailsSettingsActivity() } just runs
|
||||
}
|
||||
private val permissionsManager = FakePermissionManager()
|
||||
private val mutableEventFlow = bufferedMutableSharedFlow<AccountSecurityEvent>()
|
||||
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
|
||||
private val viewModel = mockk<AccountSecurityViewModel>(relaxed = true) {
|
||||
@@ -59,6 +63,7 @@ class AccountSecurityScreenTest : BaseComposeTest() {
|
||||
onNavigateToDeleteAccount = { onNavigateToDeleteAccountCalled = true },
|
||||
viewModel = viewModel,
|
||||
intentManager = intentManager,
|
||||
permissionsManager = permissionsManager,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -121,8 +126,10 @@ class AccountSecurityScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `on approve login requests confirm Yes should send Enabled action and hide dialog`() {
|
||||
fun `on approve login requests confirm Yes should send Enabled action and hide dialog when permission already granted`() {
|
||||
permissionsManager.checkPermissionResult = true
|
||||
mutableStateFlow.update { it.copy(isApproveLoginRequestsEnabled = false) }
|
||||
|
||||
composeTestRule
|
||||
@@ -144,6 +151,42 @@ class AccountSecurityScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `on approve login requests confirm Yes should send Enabled action and show permission dialog when permission not granted`() {
|
||||
permissionsManager.checkPermissionResult = false
|
||||
mutableStateFlow.update { it.copy(isApproveLoginRequestsEnabled = false) }
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Use this device to approve login requests made from other devices")
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Yes")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Receive push notifications for new login requests")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
composeTestRule
|
||||
.onAllNodesWithText("No thanks")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Settings")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
AccountSecurityAction.ApprovePasswordlessLoginsToggle.Enabled,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on approve login requests confirm No should send Disabled action and hide dialog`() {
|
||||
mutableStateFlow.update { it.copy(isApproveLoginRequestsEnabled = false) }
|
||||
@@ -178,6 +221,63 @@ class AccountSecurityScreenTest : BaseComposeTest() {
|
||||
.assertIsOn()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on push permission dialog No thanks should hide dialog`() {
|
||||
permissionsManager.checkPermissionResult = false
|
||||
mutableStateFlow.update { it.copy(isApproveLoginRequestsEnabled = false) }
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Use this device to approve login requests made from other devices")
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Yes")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("No thanks")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule.assertNoDialogExists()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on push permission dialog Settings should hide dialog and send confirm action`() {
|
||||
permissionsManager.checkPermissionResult = false
|
||||
mutableStateFlow.update { it.copy(isApproveLoginRequestsEnabled = false) }
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Use this device to approve login requests made from other devices")
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Yes")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Settings")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule.assertNoDialogExists()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(AccountSecurityAction.PushNotificationConfirm)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on NavigateToApplicationDataSettings should launch the correct intent`() {
|
||||
mutableEventFlow.tryEmit(AccountSecurityEvent.NavigateToApplicationDataSettings)
|
||||
|
||||
verify { intentManager.startApplicationDetailsSettingsActivity() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on pending login requests click should send PendingLoginRequestsClick`() {
|
||||
composeTestRule
|
||||
|
||||
+19
-15
@@ -312,7 +312,7 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `on ApprovePasswordlessLoginsToggle enabled should update settings, set isApprovePasswordlessLoginsEnabled to true, and display toast`() =
|
||||
fun `on ApprovePasswordlessLoginsToggle enabled should update settings and set isApprovePasswordlessLoginsEnabled to true`() =
|
||||
runTest {
|
||||
val settingsRepository = mockk<SettingsRepository> {
|
||||
every { isApprovePasswordlessLoginsEnabled = true } just runs
|
||||
@@ -324,10 +324,7 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
viewModel.trySendAction(
|
||||
AccountSecurityAction.ApprovePasswordlessLoginsToggle.Enabled,
|
||||
)
|
||||
assertEquals(
|
||||
AccountSecurityEvent.ShowToast("Handle Login requests on this device.".asText()),
|
||||
awaitItem(),
|
||||
)
|
||||
expectNoEvents()
|
||||
verify(exactly = 1) { settingsRepository.isApprovePasswordlessLoginsEnabled = true }
|
||||
}
|
||||
assertTrue(viewModel.stateFlow.value.isApproveLoginRequestsEnabled)
|
||||
@@ -335,24 +332,21 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `on ApprovePasswordlessLoginsToggle pending enabled should set isApprovePasswordlessLoginsEnabled to true and display toast`() =
|
||||
fun `on ApprovePasswordlessLoginsToggle pending enabled should set isApprovePasswordlessLoginsEnabled to true`() =
|
||||
runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(
|
||||
AccountSecurityAction.ApprovePasswordlessLoginsToggle.PendingEnabled,
|
||||
)
|
||||
assertEquals(
|
||||
AccountSecurityEvent.ShowToast("Handle Login requests on this device.".asText()),
|
||||
awaitItem(),
|
||||
)
|
||||
expectNoEvents()
|
||||
}
|
||||
assertTrue(viewModel.stateFlow.value.isApproveLoginRequestsEnabled)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `on ApprovePasswordlessLoginsToggle disabled should update settings, set isApprovePasswordlessLoginsEnabled to false, and display toast`() =
|
||||
fun `on ApprovePasswordlessLoginsToggle disabled should update settings and set isApprovePasswordlessLoginsEnabled to false`() =
|
||||
runTest {
|
||||
val settingsRepository = mockk<SettingsRepository> {
|
||||
every { isApprovePasswordlessLoginsEnabled = false } just runs
|
||||
@@ -364,10 +358,7 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
viewModel.trySendAction(
|
||||
AccountSecurityAction.ApprovePasswordlessLoginsToggle.Disabled,
|
||||
)
|
||||
assertEquals(
|
||||
AccountSecurityEvent.ShowToast("Handle Login requests on this device.".asText()),
|
||||
awaitItem(),
|
||||
)
|
||||
expectNoEvents()
|
||||
verify(exactly = 1) {
|
||||
settingsRepository.isApprovePasswordlessLoginsEnabled = false
|
||||
}
|
||||
@@ -375,6 +366,19 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
assertFalse(viewModel.stateFlow.value.isApproveLoginRequestsEnabled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on PushNotificationConfirm should send NavigateToApplicationDataSettings event`() =
|
||||
runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(AccountSecurityAction.PushNotificationConfirm)
|
||||
assertEquals(
|
||||
AccountSecurityEvent.NavigateToApplicationDataSettings,
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createViewModel(
|
||||
initialState: AccountSecurityState? = DEFAULT_STATE,
|
||||
authRepository: AuthRepository = mockk(relaxed = true),
|
||||
|
||||
Reference in New Issue
Block a user