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

View file

@ -312,10 +312,25 @@ class SettingsScreenTest : BaseComposeTest() {
composeTestRule composeTestRule
.onAllNodesWithText(text = "1", useUnmergedTree = true)[1] .onAllNodesWithText(text = "1", useUnmergedTree = true)[1]
.assertExists() .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( private val DEFAULT_STATE = SettingsState(
securityCount = 0, securityCount = 0,
autoFillCount = 0, autoFillCount = 0,
vaultCount = 0,
) )

View file

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