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:
@@ -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 auto‑adding an empty URI by setting a non‑null initial value.
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user