mirror of
https://github.com/bitwarden/android.git
synced 2026-06-01 10:16:47 -05:00
BIT-660: Adding ui for catch all email (#303)
This commit is contained in:
@@ -993,6 +993,41 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Username_CatchAllEmail state, updating text in email field should send EmailTextChange action`() {
|
||||
updateState(
|
||||
GeneratorState(
|
||||
generatedText = "Placeholder",
|
||||
selectedType = GeneratorState.MainType.Username(
|
||||
GeneratorState.MainType.Username.UsernameType.CatchAllEmail(
|
||||
domainName = "",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule.setContent {
|
||||
GeneratorScreen(viewModel = viewModel)
|
||||
}
|
||||
|
||||
val newDomain = "test.com"
|
||||
|
||||
// Find the text field for Catch-All Email and input text
|
||||
composeTestRule
|
||||
.onNodeWithText("Domain name (required)")
|
||||
.performScrollTo()
|
||||
.performTextInput(newDomain)
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
GeneratorAction.MainType.Username.UsernameType.CatchAllEmail.DomainTextChange(
|
||||
domain = newDomain,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
//endregion Username Plus Addressed Email Tests
|
||||
|
||||
private fun updateState(state: GeneratorState) {
|
||||
|
||||
@@ -27,6 +27,10 @@ class GeneratorViewModelTest : BaseViewModelTest() {
|
||||
private val initialUsernameState = createPlusAddressedEmailState()
|
||||
private val usernameSavedStateHandle = createSavedStateHandleWithState(initialUsernameState)
|
||||
|
||||
private val initialCatchAllEmailState = createCatchAllEmailState()
|
||||
private val catchAllEmailSavedStateHandle =
|
||||
createSavedStateHandleWithState(initialCatchAllEmailState)
|
||||
|
||||
private val fakeGeneratorRepository = FakeGeneratorRepository().apply {
|
||||
setMockGeneratePasswordResult(
|
||||
GeneratedPasswordResult.Success("defaultPassword"),
|
||||
@@ -826,6 +830,48 @@ class GeneratorViewModelTest : BaseViewModelTest() {
|
||||
assertEquals(expectedState, viewModel.stateFlow.value)
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
inner class CatchAllEmailActions {
|
||||
private val defaultCatchAllEmailState = createCatchAllEmailState()
|
||||
private lateinit var viewModel: GeneratorViewModel
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
viewModel = GeneratorViewModel(catchAllEmailSavedStateHandle, fakeGeneratorRepository)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `DomainTextChange should update domain correctly`() =
|
||||
runTest {
|
||||
val newDomain = "test.com"
|
||||
viewModel.actionChannel.trySend(
|
||||
GeneratorAction
|
||||
.MainType
|
||||
.Username
|
||||
.UsernameType
|
||||
.CatchAllEmail
|
||||
.DomainTextChange(
|
||||
domain = newDomain,
|
||||
),
|
||||
)
|
||||
|
||||
val expectedState = defaultCatchAllEmailState.copy(
|
||||
selectedType = GeneratorState.MainType.Username(
|
||||
selectedType = GeneratorState
|
||||
.MainType
|
||||
.Username
|
||||
.UsernameType
|
||||
.CatchAllEmail(
|
||||
domainName = newDomain,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(expectedState, viewModel.stateFlow.value)
|
||||
}
|
||||
}
|
||||
//region Helper Functions
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
@@ -888,6 +934,19 @@ class GeneratorViewModelTest : BaseViewModelTest() {
|
||||
),
|
||||
)
|
||||
|
||||
private fun createCatchAllEmailState(
|
||||
generatedText: String = "defaultCatchAllEmail",
|
||||
domain: String = "defaultDomain",
|
||||
): GeneratorState =
|
||||
GeneratorState(
|
||||
generatedText = generatedText,
|
||||
selectedType = GeneratorState.MainType.Username(
|
||||
GeneratorState.MainType.Username.UsernameType.CatchAllEmail(
|
||||
domainName = domain,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
private fun createSavedStateHandleWithState(state: GeneratorState) =
|
||||
SavedStateHandle().apply {
|
||||
set("state", state)
|
||||
|
||||
Reference in New Issue
Block a user