mirror of
https://github.com/bitwarden/android.git
synced 2026-03-21 22:00:42 -05:00
PM-16861 - Update Behavior When Tapping Same Generator Tab Already Viewing (#4653)
This commit is contained in:
@@ -801,6 +801,8 @@ class GeneratorViewModel @Inject constructor(
|
||||
//region Main Type Option Handlers
|
||||
|
||||
private fun handleMainTypeOptionSelect(action: GeneratorAction.MainTypeOptionSelect) {
|
||||
if (action.mainTypeOption == state.selectedType.mainTypeOption) return
|
||||
|
||||
when (action.mainTypeOption) {
|
||||
GeneratorState.MainTypeOption.PASSWORD -> {
|
||||
loadPasscodeOptions(selectedType = GeneratorState.MainType.Password())
|
||||
|
||||
@@ -716,22 +716,51 @@ class GeneratorViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MainTypeOptionSelect shouldn't update the state if its already selected`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
fakeGeneratorRepository.setMockGeneratePassphraseResult(
|
||||
GeneratedPassphraseResult.Success("updatedText"),
|
||||
)
|
||||
|
||||
val expectedState = initialPasscodeState.copy(
|
||||
selectedType = GeneratorState.MainType.Passphrase(),
|
||||
generatedText = "updatedText",
|
||||
)
|
||||
|
||||
val action = GeneratorAction.MainTypeOptionSelect(GeneratorState.MainTypeOption.PASSPHRASE)
|
||||
|
||||
viewModel.trySendAction(action)
|
||||
assertEquals(expectedState, viewModel.stateFlow.value)
|
||||
|
||||
fakeGeneratorRepository.setMockGeneratePassphraseResult(
|
||||
GeneratedPassphraseResult.Success("updatedTextAgain"),
|
||||
)
|
||||
|
||||
viewModel.trySendAction(action)
|
||||
assertEquals(expectedState, viewModel.stateFlow.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MainTypeOptionSelect PASSWORD should switch to Passcode`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(
|
||||
GeneratorAction.MainTypeOptionSelect(GeneratorState.MainTypeOption.USERNAME),
|
||||
)
|
||||
|
||||
fakeGeneratorRepository.setMockGeneratePasswordResult(
|
||||
GeneratedPasswordResult.Success("updatedText"),
|
||||
)
|
||||
|
||||
val action = GeneratorAction.MainTypeOptionSelect(GeneratorState.MainTypeOption.PASSWORD)
|
||||
|
||||
viewModel.trySendAction(action)
|
||||
|
||||
val expectedState = initialPasscodeState.copy(
|
||||
selectedType = GeneratorState.MainType.Password(),
|
||||
generatedText = "updatedText",
|
||||
)
|
||||
|
||||
viewModel.trySendAction(action)
|
||||
|
||||
assertEquals(expectedState, viewModel.stateFlow.value)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user