From c7708b958b0824983d24b95b7ec55eb2d7612287 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Mon, 17 Jun 2024 12:23:01 -0500 Subject: [PATCH] [PM-5189] Fixing jest tests --- .../background/overlay.background.spec.ts | 25 +++++++++++++++++++ .../autofill/background/overlay.background.ts | 12 +++++++++ 2 files changed, 37 insertions(+) diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index 466b0e9ce4..fba8e425e6 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -1346,6 +1346,31 @@ describe("OverlayBackground", () => { }); }); + describe("rebuildSubFrameOffsets", () => { + it("triggers a rebuild of the sub frame offsets of the sender", async () => { + const buildSubFrameOffsetsSpy = jest.spyOn( + overlayBackground as any, + "buildSubFrameOffsets", + ); + const tab = mock({ id: 1 }); + const frameId = 10; + subFrameOffsetsSpy[tab.id] = new Map([ + [frameId, { left: 1, top: 1, url: "https://top-frame.com" }], + ]); + const sender = mock({ tab, frameId }); + + sendMockExtensionMessage({ command: "rebuildSubFrameOffsets" }, sender); + await flushPromises(); + + expect(buildSubFrameOffsetsSpy).toHaveBeenCalledWith( + sender.tab, + frameId, + sender.url, + sender, + ); + }); + }); + describe("destroyAutofillInlineMenuListeners", () => { it("sends a message to the passed frameId that triggers a destruction of the inline menu listeners on that frame", () => { const sender = mock({ tab: { id: 1 }, frameId: 0 }); diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 88b63de237..9d398d6d6f 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -428,6 +428,12 @@ export class OverlayBackground implements OverlayBackgroundInterface { await this.rebuildSubFrameOffsets(sender); } + /** + * Triggers a delayed repositioning of the inline menu. Used in cases where the page in some way + * is resized, scrolled, or when a sub frame is interacted with. + * + * @param sender - The sender of the message + */ private delayedUpdateInlineMenuPosition(sender: chrome.runtime.MessageSender) { this.clearDelayedUpdateInlineMenuPositionTimeout(); this.delayedUpdateInlineMenuPositionTimeout = globalThis.setTimeout(async () => { @@ -593,6 +599,9 @@ export class OverlayBackground implements OverlayBackgroundInterface { } } + /** + * Clears the timeout used to trigger a delayed update of the inline menu position. + */ private clearDelayedUpdateInlineMenuPositionTimeout() { if (this.delayedUpdateInlineMenuPositionTimeout) { clearTimeout(this.delayedUpdateInlineMenuPositionTimeout); @@ -695,6 +704,9 @@ export class OverlayBackground implements OverlayBackgroundInterface { }, 150); } + /** + * Clears the timeout used to fade in the inline menu elements. + */ private clearInlineMenuFadeInTimeout() { if (this.inlineMenuFadeInTimeout) { globalThis.clearTimeout(this.inlineMenuFadeInTimeout);