From 0a09facde0fd74fdf6993228075e740d7f4f61dd Mon Sep 17 00:00:00 2001 From: Brian Yencho Date: Mon, 20 Nov 2023 11:37:26 -0600 Subject: [PATCH] Move AccountSumary to ui package and make name nullable (#259) --- .../feature/vaultunlock/VaultUnlockViewModel.kt | 2 +- .../components/BitwardenAccountSwitcher.kt | 2 +- .../platform/components}/model/AccountSummary.kt | 6 +++--- .../ui/vault/feature/vault/VaultScreen.kt | 2 +- .../ui/vault/feature/vault/VaultViewModel.kt | 2 +- .../vault/util/AccountSummaryExtensions.kt | 12 ++++++++---- .../feature/vaultunlock/VaultUnlockScreenTest.kt | 2 +- .../vaultunlock/VaultUnlockViewModelTest.kt | 2 +- .../ui/vault/feature/vault/VaultScreenTest.kt | 2 +- .../ui/vault/feature/vault/VaultViewModelTest.kt | 2 +- .../vault/util/AccountSummaryExtensionsTest.kt | 16 ++++++++++++++-- 11 files changed, 33 insertions(+), 17 deletions(-) rename app/src/main/java/com/x8bit/bitwarden/{data/auth/repository => ui/platform/components}/model/AccountSummary.kt (86%) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModel.kt index a44c98b48..378d45d9b 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModel.kt @@ -5,7 +5,6 @@ import androidx.compose.ui.graphics.Color import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.x8bit.bitwarden.R -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository import com.x8bit.bitwarden.data.vault.repository.VaultRepository import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult @@ -13,6 +12,7 @@ import com.x8bit.bitwarden.ui.platform.base.BaseViewModel import com.x8bit.bitwarden.ui.platform.base.util.Text import com.x8bit.bitwarden.ui.platform.base.util.asText import com.x8bit.bitwarden.ui.platform.base.util.hexToColor +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import com.x8bit.bitwarden.ui.platform.util.labelOrBaseUrlHost import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.launchIn diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/BitwardenAccountSwitcher.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/BitwardenAccountSwitcher.kt index 49cd6134d..dd561347e 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/BitwardenAccountSwitcher.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/BitwardenAccountSwitcher.kt @@ -37,9 +37,9 @@ import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.unit.dp import androidx.core.graphics.toColorInt import com.x8bit.bitwarden.R -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary import com.x8bit.bitwarden.ui.platform.base.util.lowercaseWithCurrentLocal import com.x8bit.bitwarden.ui.platform.base.util.toUnscaledTextUnit +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import com.x8bit.bitwarden.ui.vault.feature.vault.util.iconRes import com.x8bit.bitwarden.ui.vault.feature.vault.util.initials import com.x8bit.bitwarden.ui.vault.feature.vault.util.supportingTextResOrNull diff --git a/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/AccountSummary.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/model/AccountSummary.kt similarity index 86% rename from app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/AccountSummary.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/platform/components/model/AccountSummary.kt index 2724ec21b..28cef9850 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/AccountSummary.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/model/AccountSummary.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.data.auth.repository.model +package com.x8bit.bitwarden.ui.platform.components.model import android.os.Parcelable import kotlinx.parcelize.Parcelize @@ -7,7 +7,7 @@ import kotlinx.parcelize.Parcelize * Summary information about a user's account. * * @property userId The ID of the user. - * @property name The full name of the user. + * @property name The full name of the user (if applicable). * @property email The email of the user. * @property avatarColorHex Hex color value for a user's avatar in the "#AARRGGBB" format. * @property status The current status of the user's account locally. @@ -15,7 +15,7 @@ import kotlinx.parcelize.Parcelize @Parcelize data class AccountSummary( val userId: String, - val name: String, + val name: String?, val email: String, val avatarColorHex: String, val status: Status, diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreen.kt index 355569ede..0a9343171 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreen.kt @@ -27,7 +27,6 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.hilt.navigation.compose.hiltViewModel import com.x8bit.bitwarden.R -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect import com.x8bit.bitwarden.ui.platform.components.BitwardenAccountActionItem import com.x8bit.bitwarden.ui.platform.components.BitwardenAccountSwitcher @@ -35,6 +34,7 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenMediumTopAppBar import com.x8bit.bitwarden.ui.platform.components.BitwardenOverflowActionItem import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold import com.x8bit.bitwarden.ui.platform.components.BitwardenSearchActionItem +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import kotlinx.collections.immutable.toImmutableList /** diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModel.kt index 6bbf73a80..9f25c51dc 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultViewModel.kt @@ -6,7 +6,6 @@ import androidx.compose.ui.graphics.Color import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.x8bit.bitwarden.R -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary import com.x8bit.bitwarden.data.platform.repository.model.DataState import com.x8bit.bitwarden.data.vault.repository.VaultRepository import com.x8bit.bitwarden.data.vault.repository.model.VaultData @@ -15,6 +14,7 @@ import com.x8bit.bitwarden.ui.platform.base.util.Text import com.x8bit.bitwarden.ui.platform.base.util.asText import com.x8bit.bitwarden.ui.platform.base.util.concat import com.x8bit.bitwarden.ui.platform.base.util.hexToColor +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import com.x8bit.bitwarden.ui.vault.feature.vault.util.initials import com.x8bit.bitwarden.ui.vault.feature.vault.util.toViewState import dagger.hilt.android.lifecycle.HiltViewModel diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensions.kt index aa7835801..be59d31e8 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensions.kt @@ -3,7 +3,7 @@ package com.x8bit.bitwarden.ui.vault.feature.vault.util import androidx.annotation.DrawableRes import androidx.annotation.StringRes import com.x8bit.bitwarden.R -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary /** * Given the [AccountSummary], returns the first two "initials" found when looking at the @@ -12,13 +12,17 @@ import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary * Ex: * - "First Last" -> "FL" * - "First Second Last" -> "FS" + * - `null` -> ".." */ val AccountSummary.initials: String get() = this .name - .split(" ") - .take(2) - .joinToString(separator = "") { it.first().toString() } + ?.let { + it.split(" ") + .take(2) + .joinToString(separator = "") { it.first().toString() } + } + ?: ".." /** * Drawable resource to display for the given [AccountSummary]. diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockScreenTest.kt index 182e464b5..ee37f3e0b 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockScreenTest.kt @@ -7,9 +7,9 @@ import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollTo import androidx.compose.ui.test.performTextInput -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest import com.x8bit.bitwarden.ui.platform.base.util.asText +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import io.mockk.every import io.mockk.mockk import io.mockk.verify diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModelTest.kt index 69a0e50e9..5ff285ac8 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/vaultunlock/VaultUnlockViewModelTest.kt @@ -4,7 +4,6 @@ import androidx.lifecycle.SavedStateHandle import app.cash.turbine.test import com.x8bit.bitwarden.R import com.x8bit.bitwarden.data.auth.datasource.disk.model.EnvironmentUrlDataJson -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository import com.x8bit.bitwarden.data.platform.repository.model.Environment import com.x8bit.bitwarden.data.platform.repository.util.FakeEnvironmentRepository @@ -12,6 +11,7 @@ import com.x8bit.bitwarden.data.vault.repository.VaultRepository import com.x8bit.bitwarden.data.vault.repository.model.VaultUnlockResult import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest import com.x8bit.bitwarden.ui.platform.base.util.asText +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import io.mockk.coEvery import io.mockk.coVerify import io.mockk.every 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 8497fb8d4..3219c1b74 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 @@ -10,9 +10,9 @@ import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performScrollToNode -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest import com.x8bit.bitwarden.ui.platform.base.util.asText +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import io.mockk.every import io.mockk.mockk import io.mockk.verify 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 247755b7a..ff6591d42 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 @@ -2,7 +2,6 @@ package com.x8bit.bitwarden.ui.vault.feature.vault import androidx.lifecycle.SavedStateHandle import app.cash.turbine.test -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary import com.x8bit.bitwarden.data.platform.repository.model.DataState import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCipherView import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockFolderView @@ -10,6 +9,7 @@ import com.x8bit.bitwarden.data.vault.repository.VaultRepository import com.x8bit.bitwarden.data.vault.repository.model.VaultData import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest import com.x8bit.bitwarden.ui.platform.base.util.asText +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import io.mockk.every import io.mockk.mockk import kotlinx.coroutines.flow.MutableStateFlow diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensionsTest.kt index 6272bb085..8118e4054 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/AccountSummaryExtensionsTest.kt @@ -1,7 +1,7 @@ package com.x8bit.bitwarden.ui.vault.feature.vault.util import com.x8bit.bitwarden.R -import com.x8bit.bitwarden.data.auth.repository.model.AccountSummary +import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary import io.mockk.every import io.mockk.mockk import org.junit.jupiter.api.Assertions.assertEquals @@ -10,8 +10,9 @@ import org.junit.jupiter.api.Test class AccountSummaryExtensionsTest { + @Suppress("MaxLineLength") @Test - fun `initials should return the starting letters of the first two words in the name`() { + fun `initials should return the starting letters of the first two words in the name if present`() { assertEquals( "FS", mockk() { @@ -21,6 +22,17 @@ class AccountSummaryExtensionsTest { ) } + @Test + fun `initials should return a default value if the name is not present`() { + assertEquals( + "..", + mockk() { + every { name } returns null + } + .initials, + ) + } + @Test fun `iconRes returns a checkmark for active accounts`() { assertEquals(