test: add tests for __reloadInitiated behavior to ensure correct bookerViewed vs bookerReloaded events (#27379)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
06f4b25080
commit
3e29904d7d
1 file changed
+111
@@ -704,6 +704,117 @@ describe("Cal", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("__reloadInitiated behavior - ensures correct bookerViewed vs bookerReloaded event firing", () => {
|
||||||
|
/**
|
||||||
|
* These tests verify that __reloadInitiated is sent correctly via doInIframe,
|
||||||
|
* which determines whether bookerViewed or bookerReloaded fires in the iframe.
|
||||||
|
*
|
||||||
|
* - If __reloadInitiated is sent → iframe sets reloadInitiated=true → bookerReloaded fires
|
||||||
|
* - If __reloadInitiated is NOT sent → iframe has reloadInitiated=false → bookerViewed fires
|
||||||
|
*/
|
||||||
|
beforeEach(() => {
|
||||||
|
calInstance = new CalClass("test-namespace", []);
|
||||||
|
window.Cal.config = { forwardQueryParams: false };
|
||||||
|
vi.spyOn(calInstance, "doInIframe");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should send __reloadInitiated when fullReload action is taken (bookerReloaded should fire)", async () => {
|
||||||
|
const baseModalArgs = {
|
||||||
|
calLink: "john-doe/meeting",
|
||||||
|
config: { theme: "light", layout: "modern" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. First modal open - creates new modal (no __reloadInitiated)
|
||||||
|
await calInstance.api.modal({ ...baseModalArgs, __prerender: true });
|
||||||
|
expect(calInstance.doInIframe).not.toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ method: "__reloadInitiated" })
|
||||||
|
);
|
||||||
|
|
||||||
|
vi.mocked(calInstance.doInIframe).mockClear();
|
||||||
|
|
||||||
|
// 2. Open modal with DIFFERENT calLink - triggers fullReload
|
||||||
|
// This should send __reloadInitiated because it's a reload scenario
|
||||||
|
await calInstance.api.modal({
|
||||||
|
...baseModalArgs,
|
||||||
|
calLink: "jane-doe/meeting",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(calInstance.doInIframe).toHaveBeenCalledWith({
|
||||||
|
method: "__reloadInitiated",
|
||||||
|
arg: {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should NOT send __reloadInitiated when creating a new modal (bookerViewed should fire)", async () => {
|
||||||
|
const baseModalArgs = {
|
||||||
|
calLink: "john-doe/meeting",
|
||||||
|
config: { theme: "light", layout: "modern" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new modal - should NOT send __reloadInitiated
|
||||||
|
await calInstance.api.modal(baseModalArgs);
|
||||||
|
|
||||||
|
expect(calInstance.doInIframe).not.toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ method: "__reloadInitiated" })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should NOT send __reloadInitiated when connect action is taken (bookerViewed should fire)", async () => {
|
||||||
|
const baseModalArgs = {
|
||||||
|
calLink: "john-doe/meeting",
|
||||||
|
config: { theme: "light", layout: "modern" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// 1. Prerender the modal
|
||||||
|
await calInstance.api.modal({ ...baseModalArgs, __prerender: true });
|
||||||
|
vi.mocked(calInstance.doInIframe).mockClear();
|
||||||
|
|
||||||
|
// 2. Open modal with same calLink but different config - triggers connect (not fullReload)
|
||||||
|
await calInstance.api.modal({
|
||||||
|
...baseModalArgs,
|
||||||
|
config: { ...baseModalArgs.config, name: "John Doe" },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Should call connect, NOT __reloadInitiated
|
||||||
|
expect(calInstance.doInIframe).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ method: "connect" })
|
||||||
|
);
|
||||||
|
expect(calInstance.doInIframe).not.toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({ method: "__reloadInitiated" })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should clear stale __reloadInitiated from queue when loadInIframe is called again", () => {
|
||||||
|
// This tests the queue clearing behavior that prevents stale __reloadInitiated
|
||||||
|
// from causing bookerReloaded to fire incorrectly
|
||||||
|
|
||||||
|
// 1. Create iframe
|
||||||
|
const iframe = calInstance.createIframe({
|
||||||
|
calLink: "john-doe/meeting",
|
||||||
|
config: {},
|
||||||
|
calOrigin: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Simulate __reloadInitiated being queued (happens during fullReload)
|
||||||
|
calInstance.doInIframe({ method: "__reloadInitiated", arg: {} });
|
||||||
|
expect(calInstance.iframeDoQueue).toHaveLength(1);
|
||||||
|
expect(calInstance.iframeDoQueue[0].method).toBe("__reloadInitiated");
|
||||||
|
|
||||||
|
// 3. loadInIframe is called again (e.g., another fullReload before iframe ready)
|
||||||
|
// This should clear the queue, removing the stale __reloadInitiated
|
||||||
|
calInstance.loadInIframe({
|
||||||
|
calLink: "jane-doe/meeting",
|
||||||
|
config: {},
|
||||||
|
calOrigin: null,
|
||||||
|
iframe,
|
||||||
|
});
|
||||||
|
|
||||||
|
// 4. Queue should be cleared - stale __reloadInitiated removed
|
||||||
|
// This ensures the new iframe won't receive the old __reloadInitiated
|
||||||
|
expect(calInstance.iframeDoQueue).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("getNextActionForModal", () => {
|
describe("getNextActionForModal", () => {
|
||||||
const baseArgs = {
|
const baseArgs = {
|
||||||
pathWithQueryToLoad: "john-doe/meeting",
|
pathWithQueryToLoad: "john-doe/meeting",
|
||||||
|
|||||||
Reference in new issue
Block a user