PM-13464 show notification badge for vault settings if the showImport… (#4096)

This commit is contained in:
Dave Severns 2024-10-18 13:13:23 -04:00 committed by GitHub
parent 083578ec2b
commit c26a7cdf28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 1 deletions

View file

@ -28,6 +28,7 @@ class SettingsViewModel @Inject constructor(
initialState = SettingsState(
securityCount = firstTimeActionManager.allSecuritySettingsBadgeCountFlow.value,
autoFillCount = firstTimeActionManager.allAutofillSettingsBadgeCountFlow.value,
vaultCount = firstTimeActionManager.allVaultSettingsBadgeCountFlow.value,
),
) {
@ -35,10 +36,12 @@ class SettingsViewModel @Inject constructor(
combine(
firstTimeActionManager.allSecuritySettingsBadgeCountFlow,
firstTimeActionManager.allAutofillSettingsBadgeCountFlow,
) { securityCount, autofillCount ->
firstTimeActionManager.allVaultSettingsBadgeCountFlow,
) { securityCount, autofillCount, vaultCount ->
SettingsAction.Internal.SettingsNotificationCountUpdate(
securityCount = securityCount,
autoFillCount = autofillCount,
vaultCount = vaultCount,
)
}
.onEach(::sendAction)
@ -68,6 +71,7 @@ class SettingsViewModel @Inject constructor(
it.copy(
autoFillCount = action.autoFillCount,
securityCount = action.securityCount,
vaultCount = action.vaultCount,
)
}
}
@ -107,10 +111,12 @@ class SettingsViewModel @Inject constructor(
data class SettingsState(
private val autoFillCount: Int,
private val securityCount: Int,
private val vaultCount: Int,
) {
val notificationBadgeCountMap: Map<Settings, Int> = mapOf(
Settings.ACCOUNT_SECURITY to securityCount,
Settings.AUTO_FILL to autoFillCount,
Settings.VAULT to vaultCount,
)
}
@ -175,6 +181,7 @@ sealed class SettingsAction {
data class SettingsNotificationCountUpdate(
val autoFillCount: Int,
val securityCount: Int,
val vaultCount: Int,
) : Internal()
}
}

View file

@ -312,10 +312,25 @@ class SettingsScreenTest : BaseComposeTest() {
composeTestRule
.onAllNodesWithText(text = "1", useUnmergedTree = true)[1]
.assertExists()
mutableStateFlow.update { it.copy(vaultCount = 1) }
composeTestRule
.onAllNodesWithText(text = "1", useUnmergedTree = true)[0]
.assertExists()
composeTestRule
.onAllNodesWithText(text = "1", useUnmergedTree = true)[1]
.assertExists()
composeTestRule
.onAllNodesWithText(text = "1", useUnmergedTree = true)[2]
.assertExists()
}
}
private val DEFAULT_STATE = SettingsState(
securityCount = 0,
autoFillCount = 0,
vaultCount = 0,
)

View file

@ -19,10 +19,12 @@ import org.junit.jupiter.api.Test
class SettingsViewModelTest : BaseViewModelTest() {
private val mutableAutofillBadgeCountFlow = MutableStateFlow(0)
private val mutableVaultBadgeCountFlow = MutableStateFlow(0)
private val mutableSecurityBadgeCountFlow = MutableStateFlow(0)
private val firstTimeManager = mockk<FirstTimeActionManager> {
every { allSecuritySettingsBadgeCountFlow } returns mutableSecurityBadgeCountFlow
every { allAutofillSettingsBadgeCountFlow } returns mutableAutofillBadgeCountFlow
every { allVaultSettingsBadgeCountFlow } returns mutableVaultBadgeCountFlow
}
private val specialCircumstanceManager: SpecialCircumstanceManager = mockk {
every { specialCircumstance } returns null
@ -86,11 +88,13 @@ class SettingsViewModelTest : BaseViewModelTest() {
fun `initial state reflects the current state of the repository`() {
mutableAutofillBadgeCountFlow.update { 1 }
mutableSecurityBadgeCountFlow.update { 2 }
mutableVaultBadgeCountFlow.update { 3 }
val viewModel = createViewModel()
assertEquals(
SettingsState(
autoFillCount = 1,
securityCount = 2,
vaultCount = 3,
),
viewModel.stateFlow.value,
)
@ -104,6 +108,7 @@ class SettingsViewModelTest : BaseViewModelTest() {
SettingsState(
autoFillCount = 0,
securityCount = 0,
vaultCount = 0,
),
awaitItem(),
)
@ -113,6 +118,7 @@ class SettingsViewModelTest : BaseViewModelTest() {
SettingsState(
autoFillCount = 0,
securityCount = 2,
vaultCount = 0,
),
awaitItem(),
)
@ -122,6 +128,17 @@ class SettingsViewModelTest : BaseViewModelTest() {
SettingsState(
autoFillCount = 1,
securityCount = 2,
vaultCount = 0,
),
awaitItem(),
)
mutableVaultBadgeCountFlow.update { 3 }
assertEquals(
SettingsState(
autoFillCount = 1,
securityCount = 2,
vaultCount = 3,
),
awaitItem(),
)