Skip to content

Commit 52ecea9

Browse files
fix: add tests for embed (calcom#23561)
* fix: add tests for embed * update * fix test * fix: use immediate interpolation for cancel button link - Change from delayed evaluation (${...}) to immediate interpolation (${...}) - Remove unnecessary fallback value and complex expression - Remove frame.goto() from cancelBookingThroughEmbed as iframe already at cancel page - Remove unused page parameter from selectFirstAvailableTimeSlotNextMonth - This aligns with working pattern from line 294 and avoids parser issues with complex expressions + query params Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * chore: fix formatting in testUtils Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * fix: read popupCancelUid from URL parameter instead of copying rescheduleUid The cancel button was using the wrong booking UID because it was copying from popupRescheduleUid instead of reading from the URL parameter. This caused the embed iframe to never appear when clicking the cancel button, resulting in test timeouts. The test navigates to /?popupCancelUid=<booking_uid> which should be read by the JavaScript, just like popupRescheduleUid is read from its URL parameter. Co-Authored-By: anik@cal.com <adhabal2002@gmail.com> * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent f9b294c commit 52ecea9

4 files changed

Lines changed: 58 additions & 0 deletions

File tree

packages/embeds/embed-core/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
<script type="text/javascript" src="./playground/lib/playground-init.ts"></script>
1212
<script>
1313
let popupRescheduleUid = null;
14+
let popupCancelUid = null;
1415
let calLink = null;
1516
const initialNamespace = (url.searchParams.get("only") || "").split("ns:")[1] || "";
1617
(function defineVariables() {
1718
const searchParams = new URL(document.URL).searchParams;
1819
popupRescheduleUid = searchParams.get("popupRescheduleUid") || "qm3kwt3aTnVD7vmP9tiT2f";
20+
popupCancelUid = searchParams.get("popupCancelUid") || "qm3kwt3aTnVD7vmP9tiT2f";
1921
calLink = searchParams.get("calLink");
2022
})()
2123

@@ -292,6 +294,12 @@ <h2>Popup Examples - Reschedule Tests</h2>
292294
`<button data-cal-namespace="popupRescheduleWithRescheduleUidParam" data-cal-config='{"flag.coep":"true", "rescheduleUid": "${popupRescheduleUid}"}' data-cal-link="${calLink}">Reschedule Event(with rescheduleUid param) - Needs popupRescheduleUid and calLink param</button>`
293295
);
294296
</script>
297+
<h2>Popup Examples - Cancel Tests</h2>
298+
<script>
299+
document.write(
300+
`<button data-cal-namespace="popupCancelBooking" data-cal-config='{"flag.coep":"true"}' data-cal-link="booking/${popupCancelUid}?cancel=true">Cancel Booking - Needs popupCancelUid param</button>`
301+
);
302+
</script>
295303
<h2>Popup Examples - Different Configurations</h2>
296304
<button data-cal-namespace="popupHideEventTypeDetails" data-cal-link="free/30min" data-cal-config='{"flag.coep": "true"}'>
297305
Book Free Event [Auto Theme][uiConfig.hideEventTypeDetails=true]

packages/embeds/embed-core/playground/lib/playground.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ Cal("init", "popupRescheduleWithRescheduleUidParam", {
371371
origin: origin,
372372
});
373373

374+
Cal("init", "popupCancelBooking", {
375+
debug: true,
376+
origin: origin,
377+
});
378+
374379
Cal("init", "popupAutoTheme", {
375380
debug: true,
376381
origin: origin,

packages/embeds/embed-core/playwright/lib/testUtils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,19 @@ export async function expectActualFormResponseConnectedToQueuedFormResponse({
232232
// TODO: We should be able to verify the exact response values by correlating the form field identifiers with the actual Form from DB
233233
expect(valuesSetInResponse.length).toBe(numberOfExpectedSetFieldValues);
234234
}
235+
236+
export async function cancelBookingThroughEmbed(bookingUid: string, frame: Frame, page: Page) {
237+
await frame.waitForSelector('[data-testid="cancel_reason"]');
238+
239+
await frame.fill('[data-testid="cancel_reason"]', "Test cancellation from embed");
240+
241+
const responsePromise = page.waitForResponse("**/api/cancel");
242+
await frame.click('[data-testid="confirm_cancel"]');
243+
244+
const response = await responsePromise;
245+
expect(response.status()).toBe(200);
246+
247+
await expect(frame.locator('[data-testid="cancelled-headline"]')).toBeVisible();
248+
249+
return response;
250+
}

packages/embeds/embed-core/playwright/tests/action-based.e2e.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getBooking,
1212
deleteAllBookingsByEmail,
1313
rescheduleEvent,
14+
cancelBookingThroughEmbed,
1415
} from "../lib/testUtils";
1516

1617
// in parallel mode sometimes handleNewBooking endpoint throws "No available users found" error, this never happens in serial mode.
@@ -104,6 +105,34 @@ test.describe("Popup Tests", () => {
104105

105106
todo("Add snapshot test for embed iframe");
106107

108+
test("should be able to cancel booking through embed iframe", async ({
109+
page,
110+
embeds: { addEmbedListeners, getActionFiredDetails },
111+
}) => {
112+
const booking = await test.step("Create a booking", async () => {
113+
return await bookFirstFreeUserEventThroughEmbed({
114+
page,
115+
addEmbedListeners,
116+
getActionFiredDetails,
117+
});
118+
});
119+
120+
await test.step("Cancel the booking through embed", async () => {
121+
const calNamespace = "popupCancelBooking";
122+
await addEmbedListeners(calNamespace);
123+
await page.goto(`/?popupCancelUid=${booking.uid}`);
124+
await page.click(`[data-cal-namespace="${calNamespace}"]`);
125+
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: `/booking/${booking.uid}` });
126+
if (!embedIframe) {
127+
throw new Error("Embed iframe not found");
128+
}
129+
await cancelBookingThroughEmbed(booking.uid, embedIframe, page);
130+
});
131+
132+
const cancelledBooking = await getBooking(booking.uid);
133+
expect(cancelledBooking.status).toBe("CANCELLED");
134+
});
135+
107136
test("should open Routing Forms embed on click", async ({
108137
page,
109138
embeds: { addEmbedListeners, getActionFiredDetails },

0 commit comments

Comments
 (0)