From 991c82b27771520326eb2ed0fececadb159037cb Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Wed, 23 Oct 2024 09:09:06 -0700 Subject: [PATCH] wip --- .../NotificationCenterActionItem.kt | 2 +- .../datasource/disk/VaultDiskSourceTest.kt | 4 ++ .../disk/dao/FakeOfflineCiphersDao.kt | 46 +++++++++++++++++++ .../ui/vault/feature/vault/VaultScreenTest.kt | 2 + .../vault/feature/vault/VaultViewModelTest.kt | 1 + 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/disk/dao/FakeOfflineCiphersDao.kt diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/unsyncedvaultitem/NotificationCenterActionItem.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/unsyncedvaultitem/NotificationCenterActionItem.kt index 9996b16c3..e85b4faae 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/unsyncedvaultitem/NotificationCenterActionItem.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/unsyncedvaultitem/NotificationCenterActionItem.kt @@ -21,7 +21,7 @@ fun NotificationCenterActionItem( val contentDescription = stringResource(id = R.string.account) BitwardenStandardIconButton( - vectorIconRes = R.drawable.ic_search, + vectorIconRes = R.drawable.ic, contentDescription = contentDescription, onClick = onClick, modifier = Modifier.testTag(tag = "NotificationCenter"), diff --git a/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/disk/VaultDiskSourceTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/disk/VaultDiskSourceTest.kt index 7613fe173..a4f5eac41 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/disk/VaultDiskSourceTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/disk/VaultDiskSourceTest.kt @@ -8,6 +8,7 @@ import com.x8bit.bitwarden.data.vault.datasource.disk.dao.FakeCiphersDao import com.x8bit.bitwarden.data.vault.datasource.disk.dao.FakeCollectionsDao import com.x8bit.bitwarden.data.vault.datasource.disk.dao.FakeDomainsDao import com.x8bit.bitwarden.data.vault.datasource.disk.dao.FakeFoldersDao +import com.x8bit.bitwarden.data.vault.datasource.disk.dao.FakeOfflineCiphersDao import com.x8bit.bitwarden.data.vault.datasource.disk.dao.FakeSendsDao import com.x8bit.bitwarden.data.vault.datasource.disk.entity.CipherEntity import com.x8bit.bitwarden.data.vault.datasource.disk.entity.CollectionEntity @@ -37,6 +38,7 @@ class VaultDiskSourceTest { private val json = PlatformNetworkModule.providesJson() private val dispatcherManager: FakeDispatcherManager = FakeDispatcherManager() private lateinit var ciphersDao: FakeCiphersDao + private lateinit var offlineCiphersDao: FakeOfflineCiphersDao private lateinit var collectionsDao: FakeCollectionsDao private lateinit var domainsDao: FakeDomainsDao private lateinit var foldersDao: FakeFoldersDao @@ -47,6 +49,7 @@ class VaultDiskSourceTest { @BeforeEach fun setup() { ciphersDao = FakeCiphersDao() + offlineCiphersDao = FakeOfflineCiphersDao() collectionsDao = FakeCollectionsDao() domainsDao = FakeDomainsDao() foldersDao = FakeFoldersDao() @@ -57,6 +60,7 @@ class VaultDiskSourceTest { domainsDao = domainsDao, foldersDao = foldersDao, sendsDao = sendsDao, + offlineCiphersDao = offlineCiphersDao, json = json, dispatcherManager = dispatcherManager, ) diff --git a/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/disk/dao/FakeOfflineCiphersDao.kt b/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/disk/dao/FakeOfflineCiphersDao.kt new file mode 100644 index 000000000..1f9deeaea --- /dev/null +++ b/app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/disk/dao/FakeOfflineCiphersDao.kt @@ -0,0 +1,46 @@ +package com.x8bit.bitwarden.data.vault.datasource.disk.dao + +import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow +import com.x8bit.bitwarden.data.vault.datasource.disk.entity.OfflineCipherEntity +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +class FakeOfflineCiphersDao : OfflineCiphersDao { + + val storedCiphers = mutableListOf() + + var deleteCipherCalled: Boolean = false + var deleteCiphersCalled: Boolean = false + var insertCiphersCalled: Boolean = false + + private val ciphersFlow = bufferedMutableSharedFlow>(replay = 1) + + init { + ciphersFlow.tryEmit(emptyList()) + } + + override suspend fun deleteAllCiphers(userId: String): Int { + deleteCiphersCalled = true + val count = storedCiphers.count { it.userId == userId } + storedCiphers.removeAll { it.userId == userId } + ciphersFlow.tryEmit(storedCiphers.toList()) + return count + } + + override suspend fun deleteCipher(userId: String, cipherId: String): Int { + deleteCipherCalled = true + val count = storedCiphers.count { it.userId == userId && it.id == cipherId } + storedCiphers.removeAll { it.userId == userId && it.id == cipherId } + ciphersFlow.tryEmit(storedCiphers.toList()) + return count + } + + override suspend fun insertCiphers(ciphers: List) { + storedCiphers.addAll(ciphers) + ciphersFlow.tryEmit(ciphers.toList()) + insertCiphersCalled = true + } + + override fun getAllCiphers(userId: String): Flow> = + ciphersFlow.map { ciphers -> ciphers.filter { it.userId == userId } } +} diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt index 4565ea426..58a52d5b2 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt @@ -43,6 +43,7 @@ import com.x8bit.bitwarden.ui.util.performLockAccountClick import com.x8bit.bitwarden.ui.util.performLogoutAccountClick import com.x8bit.bitwarden.ui.util.performRemoveAccountClick import com.x8bit.bitwarden.ui.util.performYesDialogButtonClick +import com.x8bit.bitwarden.ui.vault.feature.vault.model.NotificationSummary import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterData import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterType import com.x8bit.bitwarden.ui.vault.model.VaultItemListingType @@ -1256,6 +1257,7 @@ private val DEFAULT_STATE: VaultState = VaultState( hideNotificationsDialog = true, isRefreshing = false, showImportActionCard = false, + notificationSummaries = listOf() ) private val DEFAULT_CONTENT_VIEW_STATE: VaultState.ViewState.Content = VaultState.ViewState.Content( diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt index 74455157b..8e1ad9a2f 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModelTest.kt @@ -1729,4 +1729,5 @@ private fun createMockVaultState( hideNotificationsDialog = true, showImportActionCard = true, isRefreshing = false, + notificationSummaries = listOf() )