PM-16861 - Update Behavior When Tapping Same Generator Tab Already Viewing (#4653)

This commit is contained in:
Phil Cappelli authored and GitHub committed 2025-01-31 15:02:17 +00:00
1 parent de558bf94d
commit ecc5d4ce30
2 files changed
+33 -2

No files matched your search

@@ -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)
}