1
0
mirror of https://github.com/bitwarden/browser synced 2026-03-02 19:41:26 +00:00

prevent form status changes from triggering a valueChanges emission (#17181)

- previous data within the cipher can be overwritten by the initial form data
This commit is contained in:
Nick Krantz
2025-11-06 08:28:05 -06:00
committed by GitHub
parent 3845ef388c
commit 30af9425d8
2 changed files with 21 additions and 3 deletions

View File

@@ -39,7 +39,8 @@ describe("AutofillOptionsComponent", () => {
beforeEach(async () => {
getInitialCipherView.mockClear();
cipherFormContainer = mock<CipherFormContainer>({ getInitialCipherView, formStatusChange$ });
cipherFormContainer = mock<CipherFormContainer>({ getInitialCipherView });
cipherFormContainer.formStatusChange$ = formStatusChange$.asObservable();
liveAnnouncer = mock<LiveAnnouncer>();
platformUtilsService = mock<PlatformUtilsService>();
domainSettingsService = mock<DomainSettingsService>();
@@ -266,6 +267,23 @@ describe("AutofillOptionsComponent", () => {
expect(component.autofillOptionsForm.value.uris.length).toEqual(1);
});
it("does not emit events when status changes to prevent a `valueChanges` call", () => {
fixture.detectChanges();
const enable = jest.spyOn(component.autofillOptionsForm, "enable");
const disable = jest.spyOn(component.autofillOptionsForm, "disable");
formStatusChange$.next("disabled");
fixture.detectChanges();
expect(disable).toHaveBeenCalledWith({ emitEvent: false });
formStatusChange$.next("enabled");
fixture.detectChanges();
expect(enable).toHaveBeenCalledWith({ emitEvent: false });
});
describe("Drag & Drop Functionality", () => {
beforeEach(() => {
// Prevent autoadding an empty URI by setting a nonnull initial value.

View File

@@ -140,9 +140,9 @@ export class AutofillOptionsComponent implements OnInit {
this.cipherFormContainer.formStatusChange$.pipe(takeUntilDestroyed()).subscribe((status) => {
// Disable adding new URIs when the cipher form is disabled
if (status === "disabled") {
this.autofillOptionsForm.disable();
this.autofillOptionsForm.disable({ emitEvent: false });
} else if (!this.isPartialEdit) {
this.autofillOptionsForm.enable();
this.autofillOptionsForm.enable({ emitEvent: false });
}
});
}