mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
Add persistence for isImageLoadingEnabled appearance setting (#612)
This commit is contained in:
committed by
Álison Fernandes
parent
561aabc528
commit
80084ff0fb
+30
@@ -76,6 +76,36 @@ class SettingsDiskSourceTest {
|
||||
assertNull(settingsDiskSource.getVaultTimeoutAction(userId = userId))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isIconLoadingDisabled should pull from and update SharedPreferences`() {
|
||||
val isIconLoadingDisabled = "bwPreferencesStorage:disableFavicon"
|
||||
val expected = false
|
||||
|
||||
// Assert that the default value in disk source is null
|
||||
assertNull(settingsDiskSource.isIconLoadingDisabled)
|
||||
|
||||
// Updating the shared preferences should update disk source.
|
||||
fakeSharedPreferences
|
||||
.edit()
|
||||
.putBoolean(
|
||||
isIconLoadingDisabled,
|
||||
expected,
|
||||
)
|
||||
.apply()
|
||||
assertEquals(
|
||||
expected,
|
||||
settingsDiskSource.isIconLoadingDisabled,
|
||||
)
|
||||
|
||||
// Updating the disk source updates the shared preferences
|
||||
settingsDiskSource.isIconLoadingDisabled = true
|
||||
assertTrue(
|
||||
fakeSharedPreferences.getBoolean(
|
||||
isIconLoadingDisabled, false,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getVaultTimeoutInMinutes when values are present should pull from SharedPreferences`() {
|
||||
val vaultTimeoutBaseKey = "bwPreferencesStorage:vaultTimeout"
|
||||
|
||||
+2
@@ -29,6 +29,8 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
||||
|
||||
override var appLanguage: AppLanguage? = null
|
||||
|
||||
override var isIconLoadingDisabled: Boolean? = null
|
||||
|
||||
override fun clearData(userId: String) {
|
||||
storedVaultTimeoutActions.remove(userId)
|
||||
storedVaultTimeoutInMinutes.remove(userId)
|
||||
|
||||
+13
@@ -112,6 +112,19 @@ class SettingsRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isIconLoadingDisabled should pull from and update SettingsDiskSource`() {
|
||||
assertFalse(settingsRepository.isIconLoadingDisabled)
|
||||
|
||||
// Updates to the disk source change the repository value.
|
||||
fakeSettingsDiskSource.isIconLoadingDisabled = true
|
||||
assertTrue(settingsRepository.isIconLoadingDisabled)
|
||||
|
||||
// Updates to the repository change the disk source value
|
||||
settingsRepository.isIconLoadingDisabled = false
|
||||
assertFalse(fakeSettingsDiskSource.isIconLoadingDisabled!!)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `vaultTimeout should pull from and update SettingsDiskSource for the current user`() {
|
||||
every { authDiskSource.userState?.activeUserId } returns null
|
||||
|
||||
+13
-4
@@ -23,6 +23,8 @@ class AppearanceViewModelTest : BaseViewModelTest() {
|
||||
private val mockSettingsRepository = mockk<SettingsRepository> {
|
||||
every { appLanguage } returns AppLanguage.DEFAULT
|
||||
every { appLanguage = AppLanguage.ENGLISH } just runs
|
||||
every { isIconLoadingDisabled } returns false
|
||||
every { isIconLoadingDisabled = true } just runs
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@@ -85,18 +87,25 @@ class AppearanceViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on ShowWebsiteIconsToggle should update value in state`() = runTest {
|
||||
fun `on ShowWebsiteIconsToggle should update state and store the value`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(
|
||||
DEFAULT_STATE,
|
||||
awaitItem(),
|
||||
)
|
||||
viewModel.trySendAction(AppearanceAction.ShowWebsiteIconsToggle(true))
|
||||
|
||||
viewModel.trySendAction(AppearanceAction.ShowWebsiteIconsToggle(false))
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(showWebsiteIcons = true),
|
||||
DEFAULT_STATE.copy(showWebsiteIcons = false),
|
||||
awaitItem(),
|
||||
)
|
||||
|
||||
// Since we negate the boolean in the ViewModel it should be true
|
||||
verify {
|
||||
mockSettingsRepository.isIconLoadingDisabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +138,7 @@ class AppearanceViewModelTest : BaseViewModelTest() {
|
||||
companion object {
|
||||
private val DEFAULT_STATE = AppearanceState(
|
||||
language = AppLanguage.DEFAULT,
|
||||
showWebsiteIcons = false,
|
||||
showWebsiteIcons = true,
|
||||
theme = AppearanceState.Theme.DEFAULT,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user