mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-24 21:41:33 +01:00
[PM-5189] Implementing jest tests for AutofillInlineMenuIframeServce
This commit is contained in:
parent
17fa4f57f9
commit
d3636eb96d
@ -403,6 +403,27 @@ describe("AutofillInlineMenuIframeService", () => {
|
||||
"*",
|
||||
);
|
||||
});
|
||||
|
||||
it("triggers a delayed closure of the inline menu", () => {
|
||||
jest.useFakeTimers();
|
||||
jest.spyOn(globalThis, "clearTimeout");
|
||||
autofillInlineMenuIframeService["delayedCloseTimeout"] = setTimeout(jest.fn, 100);
|
||||
|
||||
sendPortMessage(portSpy, { command: "triggerDelayedAutofillInlineMenuClosure" });
|
||||
expect(clearTimeout).toHaveBeenCalled();
|
||||
expect(autofillInlineMenuIframeService["iframe"].style.opacity).toBe("0");
|
||||
expect(autofillInlineMenuIframeService["iframe"].style.transition).toBe(
|
||||
"opacity 65ms ease-out 0s",
|
||||
);
|
||||
|
||||
jest.advanceTimersByTime(100);
|
||||
expect(autofillInlineMenuIframeService["iframe"].style.transition).toBe(
|
||||
"opacity 125ms ease-out 0s",
|
||||
);
|
||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("closeAutofillInlineMenu", {
|
||||
forceClose: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -330,6 +330,26 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
|
||||
void this.sendExtensionMessage("closeAutofillInlineMenu", { forceClose: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a delayed closure of the inline menu to ensure that click events are
|
||||
* caught if focus is programmatically redirected away from the inline menu.
|
||||
*/
|
||||
private handleDelayedAutofillInlineMenuClosure() {
|
||||
if (this.delayedCloseTimeout) {
|
||||
clearTimeout(this.delayedCloseTimeout);
|
||||
}
|
||||
|
||||
this.updateElementStyles(this.iframe, {
|
||||
transition: this.fadeOutOpacityTransition,
|
||||
opacity: "0",
|
||||
});
|
||||
|
||||
this.delayedCloseTimeout = globalThis.setTimeout(() => {
|
||||
this.updateElementStyles(this.iframe, { transition: this.fadeInOpacityTransition });
|
||||
this.forceCloseAutofillInlineMenu();
|
||||
}, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles mutations to the iframe element's attributes. This ensures that
|
||||
* the iframe element's attributes are not modified by a third party source.
|
||||
@ -407,20 +427,4 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private handleDelayedAutofillInlineMenuClosure() {
|
||||
if (this.delayedCloseTimeout) {
|
||||
clearTimeout(this.delayedCloseTimeout);
|
||||
}
|
||||
|
||||
this.updateElementStyles(this.iframe, {
|
||||
transition: this.fadeOutOpacityTransition,
|
||||
opacity: "0",
|
||||
});
|
||||
|
||||
this.delayedCloseTimeout = globalThis.setTimeout(() => {
|
||||
this.updateElementStyles(this.iframe, { transition: this.fadeInOpacityTransition });
|
||||
this.forceCloseAutofillInlineMenu();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user