From 7c07cbb145ce7fb7bc9a7f4efdc59c26dbcbf93e Mon Sep 17 00:00:00 2001 From: Jonathan Prusik Date: Mon, 20 Oct 2025 12:40:39 -0400 Subject: [PATCH] update tests --- .../browser/main-context-menu-handler.spec.ts | 10 ++-- ...rlay-notifications-content.service.spec.ts | 2 +- .../services/autofill.service.spec.ts | 1 + .../src/autofill/services/autofill.service.ts | 4 +- .../insert-autofill-content.service.spec.ts | 58 ++++++++++++++++--- .../services/domain-settings.service.ts | 4 +- 6 files changed, 61 insertions(+), 18 deletions(-) diff --git a/apps/browser/src/autofill/browser/main-context-menu-handler.spec.ts b/apps/browser/src/autofill/browser/main-context-menu-handler.spec.ts index 1348928b7e9..2b3dbcb86d1 100644 --- a/apps/browser/src/autofill/browser/main-context-menu-handler.spec.ts +++ b/apps/browser/src/autofill/browser/main-context-menu-handler.spec.ts @@ -148,7 +148,7 @@ describe("context-menu", () => { const createdMenu = await sut.init(); expect(createdMenu).toBeTruthy(); - expect(createSpy).toHaveBeenCalledTimes(10); + expect(createSpy).toHaveBeenCalledTimes(11); }); it("has menu enabled and has premium", async () => { @@ -156,7 +156,7 @@ describe("context-menu", () => { const createdMenu = await sut.init(); expect(createdMenu).toBeTruthy(); - expect(createSpy).toHaveBeenCalledTimes(11); + expect(createSpy).toHaveBeenCalledTimes(12); }); it("has menu enabled and has premium, but card type is restricted", async () => { @@ -166,7 +166,7 @@ describe("context-menu", () => { const createdMenu = await sut.init(); expect(createdMenu).toBeTruthy(); - expect(createSpy).toHaveBeenCalledTimes(10); + expect(createSpy).toHaveBeenCalledTimes(11); }); it("has menu enabled, does not have premium, and card type is restricted", async () => { billingAccountProfileStateService.hasPremiumFromAnySource$.mockReturnValue(of(false)); @@ -174,7 +174,7 @@ describe("context-menu", () => { const createdMenu = await sut.init(); expect(createdMenu).toBeTruthy(); - expect(createSpy).toHaveBeenCalledTimes(9); + expect(createSpy).toHaveBeenCalledTimes(10); }); }); @@ -283,7 +283,7 @@ describe("context-menu", () => { await sut.removeBlockedUriMenuItems(); - expect(MainContextMenuHandler["remove"]).toHaveBeenCalledTimes(5); + expect(MainContextMenuHandler["remove"]).toHaveBeenCalledTimes(6); expect(MainContextMenuHandler["remove"]).toHaveBeenCalledWith(AUTOFILL_ID); expect(MainContextMenuHandler["remove"]).toHaveBeenCalledWith(AUTOFILL_IDENTITY_ID); expect(MainContextMenuHandler["remove"]).toHaveBeenCalledWith(AUTOFILL_CARD_ID); diff --git a/apps/browser/src/autofill/overlay/notifications/content/overlay-notifications-content.service.spec.ts b/apps/browser/src/autofill/overlay/notifications/content/overlay-notifications-content.service.spec.ts index 9f344a92bfc..a0b48850d15 100644 --- a/apps/browser/src/autofill/overlay/notifications/content/overlay-notifications-content.service.spec.ts +++ b/apps/browser/src/autofill/overlay/notifications/content/overlay-notifications-content.service.spec.ts @@ -19,7 +19,7 @@ describe("OverlayNotificationsContentService", () => { beforeEach(() => { jest.useFakeTimers(); - jest.spyOn(utils, "sendExtensionMessage").mockImplementation(jest.fn()); + jest.spyOn(utils, "sendExtensionMessage").mockImplementation(async () => null); domQueryService = mock(); domElementVisibilityService = new DomElementVisibilityService(); overlayNotificationsContentService = new OverlayNotificationsContentService(); diff --git a/apps/browser/src/autofill/services/autofill.service.spec.ts b/apps/browser/src/autofill/services/autofill.service.spec.ts index 77e8c661d08..0267980e486 100644 --- a/apps/browser/src/autofill/services/autofill.service.spec.ts +++ b/apps/browser/src/autofill/services/autofill.service.spec.ts @@ -747,6 +747,7 @@ describe("AutofillService", () => { { skipUsernameOnlyFill: autofillOptions.skipUsernameOnlyFill || false, onlyEmptyFields: autofillOptions.onlyEmptyFields || false, + pageTargetingRules: {}, fillNewPassword: autofillOptions.fillNewPassword || false, allowTotpAutofill: autofillOptions.allowTotpAutofill || false, autoSubmitLogin: autofillOptions.allowTotpAutofill || false, diff --git a/apps/browser/src/autofill/services/autofill.service.ts b/apps/browser/src/autofill/services/autofill.service.ts index 6df1ba2f837..74aa99220bf 100644 --- a/apps/browser/src/autofill/services/autofill.service.ts +++ b/apps/browser/src/autofill/services/autofill.service.ts @@ -431,7 +431,6 @@ export default class AutofillService implements AutofillServiceInterface { */ async doAutoFill(options: AutoFillOptions): Promise { const tab = options.tab; - const pageTargetingRules = await this.getPageTagetingRules(tab.url); if (!tab || !options.cipher || !options.pageDetails || !options.pageDetails.length) { throw new Error("Nothing to autofill."); @@ -439,6 +438,7 @@ export default class AutofillService implements AutofillServiceInterface { let totp: string | null = null; + const pageTargetingRules = await this.getPageTagetingRules(tab.url); const activeAccount = await firstValueFrom(this.accountService.activeAccount$); const canAccessPremium = await firstValueFrom( this.billingAccountProfileStateService.hasPremiumFromAnySource$(activeAccount.id), @@ -765,7 +765,7 @@ export default class AutofillService implements AutofillServiceInterface { const filledFields: { [id: string]: AutofillField } = {}; const fields = options.cipher.fields; const pageTargetedFields = Object.keys( - options.pageTargetingRules, + options.pageTargetingRules || {}, ) as AutofillFieldQualifierType[]; const pageHasTargetingRules = !!pageTargetedFields.length; diff --git a/apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts b/apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts index 9edcdbb3a95..0fb965b3102 100644 --- a/apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts +++ b/apps/browser/src/autofill/services/insert-autofill-content.service.spec.ts @@ -409,17 +409,57 @@ describe("InsertAutofillContentService", () => { const scriptAction: FillScript = [action, opid, value]; jest.spyOn(insertAutofillContentService["autofillInsertActions"], action); - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - insertAutofillContentService["runFillScriptAction"](scriptAction, 0); + void insertAutofillContentService["runFillScriptAction"](scriptAction, 0); jest.advanceTimersByTime(20); - expect( - insertAutofillContentService["autofillInsertActions"][action], - ).toHaveBeenCalledWith({ - opid, - value, - }); + if (action === "fill_by_opid") { + expect( + insertAutofillContentService["autofillInsertActions"][action], + ).toHaveBeenCalledWith({ + opid, + value, + }); + } else { + expect( + insertAutofillContentService["autofillInsertActions"][action], + ).toHaveBeenCalledWith({ + opid, + }); + } + }); + }); + }); + + describe("given a valid fill script action and opid", () => { + const fillScriptActions: FillScriptActions[] = [ + "fill_by_targeted_field_type", + "click_on_targeted_field_type", + "focus_by_targeted_field_type", + ]; + fillScriptActions.forEach((action) => { + it(`triggers a ${action} action`, () => { + const fieldType = "username"; + const value = "value"; + const scriptAction: FillScript = [action, fieldType, value]; + jest.spyOn(insertAutofillContentService["autofillInsertActions"], action); + + void insertAutofillContentService["runFillScriptAction"](scriptAction, 0); + jest.advanceTimersByTime(20); + + if (action === "fill_by_targeted_field_type") { + expect( + insertAutofillContentService["autofillInsertActions"][action], + ).toHaveBeenCalledWith({ + fieldType, + value, + }); + } else { + expect( + insertAutofillContentService["autofillInsertActions"][action], + ).toHaveBeenCalledWith({ + fieldType, + }); + } }); }); }); diff --git a/libs/common/src/autofill/services/domain-settings.service.ts b/libs/common/src/autofill/services/domain-settings.service.ts index f4345885b22..66a93fff2d8 100644 --- a/libs/common/src/autofill/services/domain-settings.service.ts +++ b/libs/common/src/autofill/services/domain-settings.service.ts @@ -154,7 +154,9 @@ export class DefaultDomainSettingsService implements DomainSettingsService { private accountService: AccountService, ) { this.autofillTargetingRulesState = this.stateProvider.getActive(AUTOFILL_TARGETING_RULES); - this.autofillTargetingRules$ = this.autofillTargetingRulesState.state$.pipe(map((x) => (x && Object.keys(x).length) ? x : {})); + this.autofillTargetingRules$ = this.autofillTargetingRulesState.state$.pipe( + map((x) => (x && Object.keys(x).length ? x : {})), + ); this.showFaviconsState = this.stateProvider.getGlobal(SHOW_FAVICONS); this.showFavicons$ = this.showFaviconsState.state$.pipe(map((x) => x ?? true));