mirror of
https://github.com/bitwarden/android.git
synced 2026-11-20 11:37:52 -06:00
Update definition of Environment.label (#349)
This commit is contained in:
committed by
Álison Fernandes
parent
2898613876
commit
b2c2c9e563
+43
@@ -40,4 +40,47 @@ class EnvironmentExtensionsTest {
|
||||
environmentUrlData.toEnvironmentUrls(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toEnvironmentUrlsOrDefault should correctly convert US urls to the expected type`() {
|
||||
assertEquals(
|
||||
Environment.Us,
|
||||
EnvironmentUrlDataJson.DEFAULT_US.toEnvironmentUrlsOrDefault(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toEnvironmentUrlsOrDefault should correctly convert EU urls to the expected type`() {
|
||||
assertEquals(
|
||||
Environment.Eu,
|
||||
EnvironmentUrlDataJson.DEFAULT_EU.toEnvironmentUrlsOrDefault(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toEnvironmentUrlsOrDefault should correctly convert custom urls to the expected type`() {
|
||||
val environmentUrlData = EnvironmentUrlDataJson(
|
||||
base = "base",
|
||||
api = "api",
|
||||
identity = "identity",
|
||||
icon = "icon",
|
||||
notifications = "notifications",
|
||||
webVault = "webVault",
|
||||
events = "events",
|
||||
)
|
||||
assertEquals(
|
||||
Environment.SelfHosted(
|
||||
environmentUrlData = environmentUrlData,
|
||||
),
|
||||
environmentUrlData.toEnvironmentUrlsOrDefault(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toEnvironmentUrlsOrDefault should convert null types to US values`() {
|
||||
assertEquals(
|
||||
Environment.Us,
|
||||
(null as EnvironmentUrlDataJson?).toEnvironmentUrlsOrDefault(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.x8bit.bitwarden.data.platform.repository.util
|
||||
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.model.EnvironmentUrlDataJson
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class EnvironmentUrlsDataJsonExtensionsTest {
|
||||
@Test
|
||||
fun `labelOrBaseUrlHost should correctly convert US environment to the correct label`() {
|
||||
val environment = EnvironmentUrlDataJson.DEFAULT_US
|
||||
assertEquals(
|
||||
Environment.Us.label,
|
||||
environment.labelOrBaseUrlHost,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `labelOrBaseUrlHost should correctly convert EU environment to the correct label`() {
|
||||
val environment = EnvironmentUrlDataJson.DEFAULT_EU
|
||||
assertEquals(
|
||||
Environment.Eu.label,
|
||||
environment.labelOrBaseUrlHost,
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `labelOrBaseUrlHost should correctly convert self hosted environment to the correct label`() {
|
||||
val environment = EnvironmentUrlDataJson(base = "https://vault.qa.bitwarden.pw")
|
||||
assertEquals(
|
||||
"vault.qa.bitwarden.pw",
|
||||
environment.labelOrBaseUrlHost,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -210,12 +210,12 @@ class LandingScreenTest : BaseComposeTest() {
|
||||
|
||||
// Clicking to open dialog
|
||||
composeTestRule
|
||||
.onNodeWithText(Environment.Us.label.toString(resources))
|
||||
.onNodeWithText(Environment.Us.label)
|
||||
.performClick()
|
||||
|
||||
// Clicking item on dialog
|
||||
composeTestRule
|
||||
.onNodeWithText(selectedEnvironment.label.toString(resources))
|
||||
.onNodeWithText(selectedEnvironment.label)
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ import androidx.compose.ui.test.performScrollTo
|
||||
import androidx.compose.ui.test.performTextInput
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.components.BasicDialogState
|
||||
import com.x8bit.bitwarden.ui.platform.components.LoadingDialogState
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
|
||||
@@ -186,7 +185,7 @@ private val DEFAULT_STATE =
|
||||
captchaToken = null,
|
||||
isLoginButtonEnabled = false,
|
||||
passwordInput = "",
|
||||
environmentLabel = "".asText(),
|
||||
environmentLabel = "",
|
||||
loadingDialogState = LoadingDialogState.Hidden,
|
||||
errorDialogState = BasicDialogState.Hidden,
|
||||
accountSummaries = emptyList(),
|
||||
|
||||
@@ -75,7 +75,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
environmentLabel = "".asText(),
|
||||
environmentLabel = "",
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
@@ -94,7 +94,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
environmentLabel = "abc.com".asText(),
|
||||
environmentLabel = "abc.com",
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
@@ -323,7 +323,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
||||
emailAddress = "test@gmail.com",
|
||||
passwordInput = "",
|
||||
isLoginButtonEnabled = true,
|
||||
environmentLabel = Environment.Us.type.label,
|
||||
environmentLabel = Environment.Us.label,
|
||||
loadingDialogState = LoadingDialogState.Hidden,
|
||||
errorDialogState = BasicDialogState.Hidden,
|
||||
captchaToken = null,
|
||||
|
||||
+2
-3
@@ -14,7 +14,6 @@ import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollTo
|
||||
import androidx.compose.ui.test.performTextInput
|
||||
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
|
||||
@@ -154,7 +153,7 @@ class VaultUnlockScreenTest : BaseComposeTest() {
|
||||
val textAfterUpdate = "Logged in as ${DEFAULT_STATE.email} on $newEnvironmentUrl."
|
||||
composeTestRule.onNodeWithText(textBeforeUpdate).assertExists()
|
||||
composeTestRule.onNodeWithText(textAfterUpdate).assertDoesNotExist()
|
||||
mutableStateFlow.update { it.copy(environmentUrl = newEnvironmentUrl.asText()) }
|
||||
mutableStateFlow.update { it.copy(environmentUrl = newEnvironmentUrl) }
|
||||
composeTestRule.onNodeWithText(textBeforeUpdate).assertDoesNotExist()
|
||||
composeTestRule.onNodeWithText(textAfterUpdate).assertExists()
|
||||
}
|
||||
@@ -215,7 +214,7 @@ private val DEFAULT_STATE: VaultUnlockState = VaultUnlockState(
|
||||
avatarColorString = "0000FF",
|
||||
dialog = null,
|
||||
email = "bit@bitwarden.com",
|
||||
environmentUrl = DEFAULT_ENVIRONMENT_URL.asText(),
|
||||
environmentUrl = DEFAULT_ENVIRONMENT_URL,
|
||||
initials = "AU",
|
||||
passwordInput = "",
|
||||
)
|
||||
|
||||
+2
-2
@@ -60,10 +60,10 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
val viewModel = createViewModel()
|
||||
assertEquals(DEFAULT_STATE, viewModel.stateFlow.value)
|
||||
environmentRepository.environment = Environment.SelfHosted(
|
||||
environmentUrlData = EnvironmentUrlDataJson(base = "https://vault.bitwarden.eu"),
|
||||
environmentUrlData = EnvironmentUrlDataJson(base = "https://vault.qa.bitwarden.pw"),
|
||||
)
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(environmentUrl = "vault.bitwarden.eu".asText()),
|
||||
DEFAULT_STATE.copy(environmentUrl = "vault.qa.bitwarden.pw"),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
+10
-16
@@ -1,6 +1,6 @@
|
||||
package com.x8bit.bitwarden.ui.platform.util
|
||||
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.model.EnvironmentUrlDataJson
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
@@ -8,32 +8,26 @@ import org.junit.jupiter.api.Test
|
||||
|
||||
class EnvironmentExtensionsTest {
|
||||
@Test
|
||||
fun `labelOrBaseUrlHost should correctly convert US environment to the correct label`() {
|
||||
val environment = Environment.Us
|
||||
fun `displayLabel for US type should return the correct value`() {
|
||||
assertEquals(
|
||||
environment.label,
|
||||
environment.labelOrBaseUrlHost,
|
||||
"bitwarden.com".asText(),
|
||||
Environment.Type.US.displayLabel,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `labelOrBaseUrlHost should correctly convert EU environment to the correct label`() {
|
||||
val environment = Environment.Eu
|
||||
fun `displayLabel for EU type should return the correct value`() {
|
||||
assertEquals(
|
||||
environment.label,
|
||||
environment.labelOrBaseUrlHost,
|
||||
"bitwarden.eu".asText(),
|
||||
Environment.Type.EU.displayLabel,
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `labelOrBaseUrlHost should correctly convert self hosted environment to the correct label`() {
|
||||
val environment = Environment.SelfHosted(
|
||||
environmentUrlData = EnvironmentUrlDataJson(base = "https://vault.bitwarden.com"),
|
||||
)
|
||||
fun `displayLabel for SELF_HOSTED type should return the correct value`() {
|
||||
assertEquals(
|
||||
"vault.bitwarden.com".asText(),
|
||||
environment.labelOrBaseUrlHost,
|
||||
R.string.self_hosted.asText(),
|
||||
Environment.Type.SELF_HOSTED.displayLabel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user