From 873cfa51cdae0c8aebe2d1e88d8559249b4a9222 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Fri, 7 Jun 2024 11:38:09 -0500 Subject: [PATCH] [PM-5189] Adding jest tests for added methods in AutofillInit --- .../src/autofill/content/autofill-init.spec.ts | 18 ++++++++++++++++++ .../src/autofill/content/autofill-init.ts | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/apps/browser/src/autofill/content/autofill-init.spec.ts b/apps/browser/src/autofill/content/autofill-init.spec.ts index eb8ed0a36df..11b58e6e74f 100644 --- a/apps/browser/src/autofill/content/autofill-init.spec.ts +++ b/apps/browser/src/autofill/content/autofill-init.spec.ts @@ -155,6 +155,24 @@ describe("AutofillInit", () => { autofillInit.init(); }); + it("triggers extension message handlers from the AutofillOverlayContentService", () => { + autofillOverlayContentService.extensionMessageHandlers.messageHandler = jest.fn(); + + sendMockExtensionMessage({ command: "messageHandler" }, sender, sendResponse); + + expect( + autofillOverlayContentService.extensionMessageHandlers.messageHandler, + ).toHaveBeenCalled(); + }); + + it("triggers extension message handlers from the AutofillInlineMenuContentService", () => { + inlineMenuElements.extensionMessageHandlers.messageHandler = jest.fn(); + + sendMockExtensionMessage({ command: "messageHandler" }, sender, sendResponse); + + expect(inlineMenuElements.extensionMessageHandlers.messageHandler).toHaveBeenCalled(); + }); + describe("collectPageDetails", () => { it("sends the collected page details for autofill using a background script message", async () => { const pageDetails: AutofillPageDetails = { diff --git a/apps/browser/src/autofill/content/autofill-init.ts b/apps/browser/src/autofill/content/autofill-init.ts index d28af1f65fd..993b4b207a1 100644 --- a/apps/browser/src/autofill/content/autofill-init.ts +++ b/apps/browser/src/autofill/content/autofill-init.ts @@ -190,6 +190,11 @@ class AutofillInit implements AutofillInitInterface { return true; }; + /** + * Gets the extension message handler for the given command. + * + * @param command - The extension message command. + */ private getExtensionMessageHandler(command: string): CallableFunction | undefined { if (this.autofillOverlayContentService?.extensionMessageHandlers?.[command]) { return this.autofillOverlayContentService.extensionMessageHandlers[command];