PM-10631 store when the user selects to turn auto fill on later (#3925)

This commit is contained in:
Dave Severns 2024-09-20 09:39:27 -04:00 committed by GitHub
parent 3238279290
commit 5667a1cfd0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 120 additions and 3 deletions

View file

@ -258,4 +258,16 @@ interface SettingsDiskSource {
* @see [storeUseHasLoggedInPreviously] * @see [storeUseHasLoggedInPreviously]
*/ */
fun getUserHasSignedInPreviously(userId: String): Boolean fun getUserHasSignedInPreviously(userId: String): Boolean
/**
* Gets whether or not the given [userId] has signalled they want to enable autofill in
* onboarding.
*/
fun getShowAutoFillSettingBadge(userId: String): Boolean?
/**
* Stores the given value for whether or not the given [userId] has signalled they want to
* enable autofill in onboarding.
*/
fun storeShowAutoFillSettingBadge(userId: String, showBadge: Boolean?)
} }

View file

@ -33,6 +33,7 @@ private const val CRASH_LOGGING_ENABLED_KEY = "crashLoggingEnabled"
private const val CLEAR_CLIPBOARD_INTERVAL_KEY = "clearClipboard" private const val CLEAR_CLIPBOARD_INTERVAL_KEY = "clearClipboard"
private const val INITIAL_AUTOFILL_DIALOG_SHOWN = "addSitePromptShown" private const val INITIAL_AUTOFILL_DIALOG_SHOWN = "addSitePromptShown"
private const val HAS_USER_LOGGED_IN_OR_CREATED_AN_ACCOUNT_KEY = "hasUserLoggedInOrCreatedAccount" private const val HAS_USER_LOGGED_IN_OR_CREATED_AN_ACCOUNT_KEY = "hasUserLoggedInOrCreatedAccount"
private const val SHOW_AUTOFILL_SETTING_BADGE = "showAutofillSettingBadge"
/** /**
* Primary implementation of [SettingsDiskSource]. * Primary implementation of [SettingsDiskSource].
@ -395,4 +396,15 @@ class SettingsDiskSourceImpl(
getBoolean( getBoolean(
key = HAS_USER_LOGGED_IN_OR_CREATED_AN_ACCOUNT_KEY.appendIdentifier(userId), key = HAS_USER_LOGGED_IN_OR_CREATED_AN_ACCOUNT_KEY.appendIdentifier(userId),
) == true ) == true
override fun getShowAutoFillSettingBadge(userId: String): Boolean? =
getBoolean(
key = SHOW_AUTOFILL_SETTING_BADGE.appendIdentifier(userId),
)
override fun storeShowAutoFillSettingBadge(userId: String, showBadge: Boolean?) =
putBoolean(
key = SHOW_AUTOFILL_SETTING_BADGE.appendIdentifier(userId),
value = showBadge,
)
} }

View file

@ -254,4 +254,16 @@ interface SettingsRepository {
* Record that a user has logged in on this device. * Record that a user has logged in on this device.
*/ */
fun storeUserHasLoggedInValue(userId: String) fun storeUserHasLoggedInValue(userId: String)
/**
* Gets whether or not the given [userId] has signalled they want to enable autofill in
* onboarding.
*/
fun getShowAutoFillSettingBadge(userId: String): Boolean
/**
* Stores the given value for whether or not the given [userId] has signalled they want to
* enable autofill in onboarding.
*/
fun storeShowAutoFillSettingBadge(userId: String, showBadge: Boolean)
} }

View file

@ -538,6 +538,13 @@ class SettingsRepositoryImpl(
settingsDiskSource.storeUseHasLoggedInPreviously(userId) settingsDiskSource.storeUseHasLoggedInPreviously(userId)
} }
override fun getShowAutoFillSettingBadge(userId: String): Boolean =
settingsDiskSource.getShowAutoFillSettingBadge(userId) ?: false
override fun storeShowAutoFillSettingBadge(userId: String, showBadge: Boolean) {
settingsDiskSource.storeShowAutoFillSettingBadge(userId, showBadge)
}
/** /**
* If there isn't already one generated, generate a symmetric sync key that would be used * If there isn't already one generated, generate a symmetric sync key that would be used
* for communicating via IPC. * for communicating via IPC.

View file

@ -78,7 +78,7 @@ class SetupAutoFillViewModel @Inject constructor(
} }
private fun handleTurnOnLaterConfirmClick() { private fun handleTurnOnLaterConfirmClick() {
// TODO PM-10631 record user chose to turn on later for settings badging. settingsRepository.storeShowAutoFillSettingBadge(state.userId, true)
updateOnboardingStatusToNextStep() updateOnboardingStatusToNextStep()
} }

View file

@ -1029,4 +1029,28 @@ class SettingsDiskSourceTest {
fun `hasUserSignedInPreviously returns false if value is not present in shared preferences`() { fun `hasUserSignedInPreviously returns false if value is not present in shared preferences`() {
assertFalse(settingsDiskSource.getUserHasSignedInPreviously(userId = "haveNotSignedIn")) assertFalse(settingsDiskSource.getUserHasSignedInPreviously(userId = "haveNotSignedIn"))
} }
@Test
fun `storeShowAutoFillSettingBadge should update SharedPreferences`() {
val mockUserId = "mockUserId"
val showAutofillSettingBadgeKey =
"bwPreferencesStorage:showAutofillSettingBadge_$mockUserId"
settingsDiskSource.storeShowAutoFillSettingBadge(
userId = mockUserId,
showBadge = true,
)
assertTrue(fakeSharedPreferences.getBoolean(showAutofillSettingBadgeKey, false))
}
@Test
fun `getShowAutoFillSettingBadge should pull value from shared preferences`() {
val mockUserId = "mockUserId"
val showAutofillSettingBadgeKey =
"bwPreferencesStorage:showAutofillSettingBadge_$mockUserId"
fakeSharedPreferences.edit {
putBoolean(showAutofillSettingBadgeKey, true)
}
assertTrue(settingsDiskSource.getShowAutoFillSettingBadge(userId = mockUserId)!!)
}
} }

View file

@ -61,6 +61,7 @@ class FakeSettingsDiskSource : SettingsDiskSource {
private var storedSystemBiometricIntegritySource: String? = null private var storedSystemBiometricIntegritySource: String? = null
private val storedAccountBiometricIntegrityValidity = mutableMapOf<String, Boolean?>() private val storedAccountBiometricIntegrityValidity = mutableMapOf<String, Boolean?>()
private val userSignIns = mutableMapOf<String, Boolean>() private val userSignIns = mutableMapOf<String, Boolean>()
private val userShowAutoFillBadge = mutableMapOf<String, Boolean?>()
override var appLanguage: AppLanguage? = null override var appLanguage: AppLanguage? = null
@ -284,6 +285,13 @@ class FakeSettingsDiskSource : SettingsDiskSource {
override fun getUserHasSignedInPreviously(userId: String): Boolean = userSignIns[userId] == true override fun getUserHasSignedInPreviously(userId: String): Boolean = userSignIns[userId] == true
override fun getShowAutoFillSettingBadge(userId: String): Boolean? =
userShowAutoFillBadge[userId]
override fun storeShowAutoFillSettingBadge(userId: String, showBadge: Boolean?) {
userShowAutoFillBadge[userId] = showBadge
}
private fun getMutableScreenCaptureAllowedFlow(userId: String): MutableSharedFlow<Boolean?> { private fun getMutableScreenCaptureAllowedFlow(userId: String): MutableSharedFlow<Boolean?> {
return mutableScreenCaptureAllowedFlowMap.getOrPut(userId) { return mutableScreenCaptureAllowedFlowMap.getOrPut(userId) {
bufferedMutableSharedFlow(replay = 1) bufferedMutableSharedFlow(replay = 1)

View file

@ -1148,6 +1148,33 @@ class SettingsRepositoryTest {
fakeAuthDiskSource.userState = MOCK_USER_STATE fakeAuthDiskSource.userState = MOCK_USER_STATE
assertFalse(settingsRepository.isAuthenticatorSyncEnabled) assertFalse(settingsRepository.isAuthenticatorSyncEnabled)
} }
@Test
fun `storeShowAutoFillSettingBadge should store value of false to disk`() {
val userId = "userId"
settingsRepository.storeShowAutoFillSettingBadge(userId = userId, showBadge = false)
assertFalse(fakeSettingsDiskSource.getShowAutoFillSettingBadge(userId = userId)!!)
}
@Test
fun `storeShowAutoFillSettingBadge should store value of true to disk`() {
val userId = "userId"
settingsRepository.storeShowAutoFillSettingBadge(userId = userId, showBadge = true)
assertTrue(fakeSettingsDiskSource.getShowAutoFillSettingBadge(userId = userId)!!)
}
@Test
fun `getShowAutoFillSettingBadge get value of false if does not exist`() {
val userId = "userId"
assertFalse(settingsRepository.getShowAutoFillSettingBadge(userId = userId))
}
@Test
fun `getShowAutoFillSettingBadge should return the value saved to disk`() {
val userId = "userId"
fakeSettingsDiskSource.storeShowAutoFillSettingBadge(userId = userId, showBadge = true)
assertTrue(settingsRepository.getShowAutoFillSettingBadge(userId = userId))
}
} }
private const val USER_ID: String = "userId" private const val USER_ID: String = "userId"

View file

@ -22,9 +22,10 @@ import org.junit.jupiter.api.Test
class SetupAutoFillViewModelTest : BaseViewModelTest() { class SetupAutoFillViewModelTest : BaseViewModelTest() {
private val mutableAutoFillEnabledStateFlow = MutableStateFlow(false) private val mutableAutoFillEnabledStateFlow = MutableStateFlow(false)
private val settingsRepository = mockk<SettingsRepository>(relaxed = true) { private val settingsRepository = mockk<SettingsRepository> {
every { isAutofillEnabledStateFlow } returns mutableAutoFillEnabledStateFlow every { isAutofillEnabledStateFlow } returns mutableAutoFillEnabledStateFlow
every { disableAutofill() } just runs every { disableAutofill() } just runs
every { storeShowAutoFillSettingBadge(any(), any()) } just runs
} }
private val mockUserState = mockk<UserState> { private val mockUserState = mockk<UserState> {
@ -127,8 +128,22 @@ class SetupAutoFillViewModelTest : BaseViewModelTest() {
) )
} }
} }
@Test
fun `handleTurnOnLaterConfirmClick sets showAutoFillSettingBadge to true`() {
val viewModel = createViewModel()
viewModel.trySendAction(SetupAutoFillAction.TurnOnLaterConfirmClick)
verify {
settingsRepository.storeShowAutoFillSettingBadge(
userId = DEFAULT_USER_ID,
showBadge = true,
)
}
}
private fun createViewModel() = SetupAutoFillViewModel(settingsRepository, authRepository) private fun createViewModel() = SetupAutoFillViewModel(
settingsRepository = settingsRepository,
authRepository = authRepository,
)
} }
private const val DEFAULT_USER_ID = "userId" private const val DEFAULT_USER_ID = "userId"