* fix: ESC key handler only works once in embed modal Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com> * Fix bug found by cubic and add tests --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import "../../test/__mocks__/windowMatchMedia";
|
|
|
|
import { describe, it, expect, beforeEach, vi, afterEach } from "vitest";
|
|
|
|
import { EmbedElement } from "../EmbedElement";
|
|
import { ModalBox } from "./ModalBox";
|
|
|
|
function setupWindowCal() {
|
|
// Mock window.Cal.__css which is required by ModalBox constructor
|
|
if (!window.Cal) {
|
|
// @ts-expect-error - Test setup
|
|
window.Cal = {};
|
|
}
|
|
window.Cal.__css = "/* mock css */";
|
|
}
|
|
|
|
// Register ModalBox as a custom element for testing
|
|
if (!customElements.get("cal-modal-box")) {
|
|
customElements.define("cal-modal-box", ModalBox);
|
|
}
|
|
|
|
describe("ModalBox", () => {
|
|
let modalBox: ModalBox;
|
|
|
|
beforeEach(() => {
|
|
setupWindowCal();
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (modalBox && modalBox.parentNode) {
|
|
document.body.removeChild(modalBox);
|
|
}
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("should verify that connectedCallback and disconnectedCallback of ModalBox call the EmbedElement's methods", () => {
|
|
const embedElementConnectedCallbackSpy = vi.spyOn(EmbedElement.prototype, "connectedCallback");
|
|
const embedElementDisconnectedCallbackSpy = vi.spyOn(EmbedElement.prototype, "disconnectedCallback");
|
|
|
|
modalBox = new ModalBox();
|
|
|
|
document.body.appendChild(modalBox);
|
|
|
|
expect(embedElementConnectedCallbackSpy).toHaveBeenCalledTimes(1);
|
|
|
|
document.body.removeChild(modalBox);
|
|
|
|
expect(embedElementDisconnectedCallbackSpy).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|