mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-22 16:29:09 +01:00
[PM-5189] Fixing jest tests
This commit is contained in:
parent
1e035696e8
commit
c7708b958b
@ -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<chrome.tabs.Tab>({ id: 1 });
|
||||
const frameId = 10;
|
||||
subFrameOffsetsSpy[tab.id] = new Map([
|
||||
[frameId, { left: 1, top: 1, url: "https://top-frame.com" }],
|
||||
]);
|
||||
const sender = mock<chrome.runtime.MessageSender>({ 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<chrome.runtime.MessageSender>({ tab: { id: 1 }, frameId: 0 });
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user