[PM-44412] fix: Keep autofill context after editing cipher (#7448)

This commit is contained in:
aj-rosado
2026-10-06 16:22:10 +00:00
committed by GitHub
parent ed5048141b
commit 098c08a189
2 changed files with 50 additions and 1 deletions
@@ -2069,7 +2069,9 @@ class VaultAddEditViewModel @Inject constructor(
}
is UpdateCipherResult.Success -> {
specialCircumstanceManager.specialCircumstance = null
if (state.shouldClearSpecialCircumstance) {
specialCircumstanceManager.specialCircumstance = null
}
if (state.shouldExitOnSave) {
sendEvent(event = VaultAddEditEvent.ExitApp)
} else {
@@ -2117,6 +2117,53 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
}
}
@Suppress("MaxLineLength")
@Test
fun `in edit mode during autofill selection, SaveClick should navigate back without clearing special circumstances`() =
runTest {
specialCircumstanceManager.specialCircumstance =
SpecialCircumstance.AutofillSelection(
autofillSelectionData = AutofillSelectionData(
type = AutofillSelectionData.Type.LOGIN,
framework = AutofillSelectionData.Framework.AUTOFILL,
uri = "mockUri",
),
shouldFinishWhenComplete = true,
)
val stateWithName = createVaultAddItemState(
vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_ITEM_ID),
commonContentViewState = createCommonContentViewState(name = "mockName-1"),
shouldExitOnSave = false,
shouldClearSpecialCircumstance = false,
)
mutableVaultDataFlow.value = DataState.Loaded(
data = createVaultData(cipherListView = createMockCipherListView(1)),
)
val viewModel = createAddVaultItemViewModel(
createSavedStateHandleWithState(
state = stateWithName,
vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_ITEM_ID),
vaultItemCipherType = VaultItemCipherType.LOGIN,
),
)
coEvery {
vaultRepository.updateCipher(DEFAULT_ITEM_ID, any())
} returns UpdateCipherResult.Success
viewModel.eventFlow.test {
viewModel.trySendAction(VaultAddEditAction.Common.SaveClick)
assertEquals(VaultAddEditEvent.NavigateBack, awaitItem())
}
assertNotNull(specialCircumstanceManager.specialCircumstance)
verify(exactly = 1) {
snackbarRelayManager.sendSnackbarData(
data = BitwardenSnackbarData(BitwardenString.login_saved.asText()),
relay = SnackbarRelay.CIPHER_UPDATED,
)
}
}
@Suppress("MaxLineLength")
@Test
fun `in edit mode, SaveClick updateCipher error with a null message should show an error dialog with a generic message`() =