From 1e035696e89200dc674ecfabf7ccaecb165858cd Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Mon, 17 Jun 2024 11:13:51 -0500 Subject: [PATCH] [PM-5189] Fixing jest tests --- .../background/overlay.background.spec.ts | 35 +++++++++++-------- .../autofill/content/autofill-init.spec.ts | 8 ++--- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index 74368a1098b..466b0e9ce46 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -282,7 +282,7 @@ describe("OverlayBackground", () => { it("will attempt to build the sub frame offsets by posting window messages if a set of offsets is not returned", async () => { const tab = createChromeTabMock({ id: tabId }); const frameId = 1; - tabsSendMessageSpy.mockResolvedValueOnce(null); + tabsSendMessageSpy.mockResolvedValue(null); sendMockExtensionMessage( { command: "collectPageDetailsResponse", details: createAutofillPageDetailsMock() }, mock({ tab, frameId }), @@ -384,12 +384,12 @@ describe("OverlayBackground", () => { it("rebuilds the sub frame offsets for a given tab", async () => { const sender = mock({ tab, frameId: middleFrameId }); - sendMockExtensionMessage({ command: "repositionInlineMenuForSubFrame" }, sender); + sendMockExtensionMessage({ command: "repositionAutofillInlineMenuForSubFrame" }, sender); await flushPromises(); expect(getFrameDetailsSpy).toHaveBeenCalledWith({ tabId, frameId: topFrameId }); expect(getFrameDetailsSpy).toHaveBeenCalledWith({ tabId, frameId: bottomFrameId }); - expect(getFrameDetailsSpy).not.toHaveBeenCalledWith({ tabId, frameId: middleFrameId }); + expect(getFrameDetailsSpy).toHaveBeenCalledWith({ tabId, frameId: middleFrameId }); }); it("triggers an update of the inline menu position after rebuilding sub frames", async () => { @@ -399,7 +399,10 @@ describe("OverlayBackground", () => { jest.spyOn(overlayBackground as any, "updateInlineMenuPositionAfterSubFrameRebuild"); sendMockExtensionMessage( - { command: "repositionInlineMenuForSubFrame", triggerInlineMenuPositionUpdate: true }, + { + command: "repositionAutofillInlineMenuForSubFrame", + triggerInlineMenuPositionUpdate: true, + }, sender, ); await flushPromises(); @@ -458,7 +461,10 @@ describe("OverlayBackground", () => { it("updates the position of the inline menu elements", async () => { sendMockExtensionMessage( - { command: "repositionInlineMenuForSubFrame", triggerInlineMenuPositionUpdate: true }, + { + command: "repositionAutofillInlineMenuForSubFrame", + triggerInlineMenuPositionUpdate: true, + }, sender, ); await flushInlineMenuUpdatePromises(); @@ -491,7 +497,10 @@ describe("OverlayBackground", () => { }); sendMockExtensionMessage( - { command: "repositionInlineMenuForSubFrame", triggerInlineMenuPositionUpdate: true }, + { + command: "repositionAutofillInlineMenuForSubFrame", + triggerInlineMenuPositionUpdate: true, + }, sender, ); await flushInlineMenuUpdatePromises(); @@ -1154,15 +1163,13 @@ describe("OverlayBackground", () => { overlayElement: AutofillOverlayElement.List, }); await flushPromises(); - jest.advanceTimersByTime(50); + jest.advanceTimersByTime(150); expect(buttonPortSpy.postMessage).toHaveBeenCalledWith({ - command: "updateAutofillInlineMenuPosition", - styles: { opacity: "1" }, + command: "fadeInAutofillInlineMenuIframe", }); expect(listPortSpy.postMessage).toHaveBeenCalledWith({ - command: "updateAutofillInlineMenuPosition", - styles: { opacity: "1" }, + command: "fadeInAutofillInlineMenuIframe", }); }); }); @@ -1198,14 +1205,14 @@ describe("OverlayBackground", () => { command: "toggleAutofillInlineMenuHidden", styles: { display: "none", - opacity: 1, + opacity: "1", }, }); expect(listPortSpy.postMessage).toHaveBeenCalledWith({ command: "toggleAutofillInlineMenuHidden", styles: { display: "none", - opacity: 1, + opacity: "1", }, }); }); @@ -1441,7 +1448,7 @@ describe("OverlayBackground", () => { sendResponse, ); - expect(returnValue).toBe(undefined); + expect(returnValue).toBe(null); expect(sendResponse).not.toHaveBeenCalled(); }); }); diff --git a/apps/browser/src/autofill/content/autofill-init.spec.ts b/apps/browser/src/autofill/content/autofill-init.spec.ts index de4854548cb..e27e8ef73d0 100644 --- a/apps/browser/src/autofill/content/autofill-init.spec.ts +++ b/apps/browser/src/autofill/content/autofill-init.spec.ts @@ -106,15 +106,15 @@ describe("AutofillInit", () => { sender = mock(); }); - it("returns a undefined value if a extension message handler is not found with the given message command", () => { + it("returns a null value if a extension message handler is not found with the given message command", () => { message.command = "unknownCommand"; const response = autofillInit["handleExtensionMessage"](message, sender, sendResponse); - expect(response).toBe(undefined); + expect(response).toBe(null); }); - it("returns a undefined value if the message handler does not return a response", async () => { + it("returns a null value if the message handler does not return a response", async () => { const response1 = await autofillInit["handleExtensionMessage"](message, sender, sendResponse); await flushPromises(); @@ -126,7 +126,7 @@ describe("AutofillInit", () => { const response2 = autofillInit["handleExtensionMessage"](message, sender, sendResponse); await flushPromises(); - expect(response2).toBe(undefined); + expect(response2).toBe(null); }); it("returns a true value and calls sendResponse if the message handler returns a response", async () => {