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

This commit is contained in:
Phil Cappelli
2025-01-31 10:02:17 -05:00
committed by GitHub
parent de558bf94d
commit ecc5d4ce30
2 changed files with 33 additions and 2 deletions

View File

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

View File

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