Skip to content

Commit

Permalink
test: New Booker Tests for Embed (calcom#9666)
Browse files Browse the repository at this point in the history
  • Loading branch information
hariombalhara authored Jun 26, 2023
1 parent 79b3875 commit 2272da5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 57 deletions.
20 changes: 12 additions & 8 deletions packages/embeds/embed-core/playwright/lib/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function selectFirstAvailableTimeSlotNextMonth(frame: Frame, page: Page) {
await frame.click('[data-testid="time"]');
}

export async function bookFirstEvent(username: string, frame: Frame, page: Page) {
export async function bookFirstEvent(username: string, frame: Frame, page: Page, bookerVariant: string) {
// Click first event type on Profile Page
await frame.click('[data-testid="event-type-link"]');
await frame.waitForURL((url) => {
Expand All @@ -125,9 +125,11 @@ export async function bookFirstEvent(username: string, frame: Frame, page: Page)
// Remove /embed from the end if present.
const eventSlug = new URL(frame.url()).pathname.replace(/\/embed$/, "");
await selectFirstAvailableTimeSlotNextMonth(frame, page);
await frame.waitForURL((url) => {
return url.pathname.includes(`/${username}/book`);
});
if (bookerVariant !== "new-booker") {
await frame.waitForURL((url) => {
return url.pathname.includes(`/${username}/book`);
});
}
// expect(await page.screenshot()).toMatchSnapshot("booking-page.png");
// --- fill form
await frame.fill('[name="name"]', "Embed User");
Expand All @@ -150,11 +152,13 @@ export async function bookFirstEvent(username: string, frame: Frame, page: Page)
return booking;
}

export async function rescheduleEvent(username: string, frame: Frame, page: Page) {
export async function rescheduleEvent(username: string, frame: Frame, page: Page, bookerVariant: string) {
await selectFirstAvailableTimeSlotNextMonth(frame, page);
await frame.waitForURL((url: { pathname: string | string[] }) => {
return url.pathname.includes(`/${username}/book`);
});
if (bookerVariant !== "new-booker") {
await frame.waitForURL((url: { pathname: string | string[] }) => {
return url.pathname.includes(`/${username}/book`);
});
}
// --- fill form
await frame.press('[name="email"]', "Enter");
await frame.click("[data-testid=confirm-reschedule-button]");
Expand Down
12 changes: 8 additions & 4 deletions packages/embeds/embed-core/playwright/tests/action-based.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from "@playwright/test";

import { test } from "@calcom/web/playwright/lib/fixtures";
import type { Fixtures } from "@calcom/web/playwright/lib/fixtures";
import { testBothBookers } from "@calcom/web/playwright/lib/new-booker";

import {
todo,
Expand All @@ -17,10 +18,12 @@ async function bookFirstFreeUserEventThroughEmbed({
addEmbedListeners,
page,
getActionFiredDetails,
bookerVariant,
}: {
addEmbedListeners: Fixtures["addEmbedListeners"];
page: Page;
getActionFiredDetails: Fixtures["getActionFiredDetails"];
bookerVariant: string;
}) {
const embedButtonLocator = page.locator('[data-cal-link="free"]').first();
await page.goto("/");
Expand All @@ -40,11 +43,11 @@ async function bookFirstFreeUserEventThroughEmbed({
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
const booking = await bookFirstEvent("free", embedIframe, page);
const booking = await bookFirstEvent("free", embedIframe, page, bookerVariant);
return booking;
}

test.describe("Popup Tests", () => {
testBothBookers.describe("Popup Tests", (bookerVariant) => {
test.afterEach(async () => {
await deleteAllBookingsByEmail("[email protected]");
});
Expand Down Expand Up @@ -72,7 +75,7 @@ test.describe("Popup Tests", () => {
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
const { uid: bookingId } = await bookFirstEvent("free", embedIframe, page);
const { uid: bookingId } = await bookFirstEvent("free", embedIframe, page, bookerVariant);
const booking = await getBooking(bookingId);

expect(booking.attendees.length).toBe(1);
Expand All @@ -85,6 +88,7 @@ test.describe("Popup Tests", () => {
page,
addEmbedListeners,
getActionFiredDetails,
bookerVariant,
});
});

Expand All @@ -97,7 +101,7 @@ test.describe("Popup Tests", () => {
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
await rescheduleEvent("free", embedIframe, page);
await rescheduleEvent("free", embedIframe, page, bookerVariant);
});
});

Expand Down
55 changes: 29 additions & 26 deletions packages/embeds/embed-core/playwright/tests/inline.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import { expect } from "@playwright/test";

import { test } from "@calcom/web/playwright/lib/fixtures";
import { testBothBookers } from "@calcom/web/playwright/lib/new-booker";

import { bookFirstEvent, deleteAllBookingsByEmail, getEmbedIframe, todo } from "../lib/testUtils";

test("Inline Iframe - Configured with Dark Theme", async ({
page,
getActionFiredDetails,
addEmbedListeners,
}) => {
await deleteAllBookingsByEmail("[email protected]");
await addEmbedListeners("");
await page.goto("/?only=ns:default");
const calNamespace = "";
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: "/pro" });
expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/pro",
searchParams: {
theme: "dark",
},
testBothBookers.describe("Inline Iframe", (bookerVariant) => {
test("Inline Iframe - Configured with Dark Theme", async ({
page,
getActionFiredDetails,
addEmbedListeners,
}) => {
await deleteAllBookingsByEmail("[email protected]");
await addEmbedListeners("");
await page.goto("/?only=ns:default");
const calNamespace = "";
const embedIframe = await getEmbedIframe({ calNamespace, page, pathname: "/pro" });
expect(embedIframe).toBeEmbedCalLink(calNamespace, getActionFiredDetails, {
pathname: "/pro",
searchParams: {
theme: "dark",
},
});
// expect(await page.screenshot()).toMatchSnapshot("event-types-list.png");
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
await bookFirstEvent("pro", embedIframe, page, bookerVariant);
await deleteAllBookingsByEmail("[email protected]");
});
// expect(await page.screenshot()).toMatchSnapshot("event-types-list.png");
if (!embedIframe) {
throw new Error("Embed iframe not found");
}
await bookFirstEvent("pro", embedIframe, page);
await deleteAllBookingsByEmail("[email protected]");
});

todo(
"Ensure that on all pages - [user], [user]/[type], team/[slug], team/[slug]/book, UI styling works if these pages are directly linked in embed"
);
todo(
"Ensure that on all pages - [user], [user]/[type], team/[slug], team/[slug]/book, UI styling works if these pages are directly linked in embed"
);

todo("Check that UI Configuration doesn't work for Free Plan");
todo("Check that UI Configuration doesn't work for Free Plan");
});
39 changes: 21 additions & 18 deletions packages/embeds/embed-core/playwright/tests/preview.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { expect } from "@playwright/test";

import { test } from "@calcom/web/playwright/lib/fixtures";
import { testBothBookers } from "@calcom/web/playwright/lib/new-booker";

test("Preview - embed-core should load", async ({ page }) => {
await page.goto("http://localhost:3000/embed/preview.html");
const libraryLoaded = await page.evaluate(() => {
return new Promise((resolve) => {
setInterval(() => {
if (
(
window as unknown as {
Cal: {
__css: string;
};
}
).Cal.__css
) {
resolve(true);
}
}, 1000);
testBothBookers.describe("Preview", () => {
test("Preview - embed-core should load", async ({ page }) => {
await page.goto("http://localhost:3000/embed/preview.html");
const libraryLoaded = await page.evaluate(() => {
return new Promise((resolve) => {
setInterval(() => {
if (
(
window as unknown as {
Cal: {
__css: string;
};
}
).Cal.__css
) {
resolve(true);
}
}, 1000);
});
});
expect(libraryLoaded).toBe(true);
});
expect(libraryLoaded).toBe(true);
});
3 changes: 2 additions & 1 deletion packages/embeds/embed-react/playwright/tests/basic.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { expect } from "@playwright/test";

import { getEmbedIframe } from "@calcom/embed-core/playwright/lib/testUtils";
import { test } from "@calcom/web/playwright/lib/fixtures";
import { testBothBookers } from "@calcom/web/playwright/lib/new-booker";

test.describe("Inline Embed", () => {
testBothBookers.describe("Inline Embed", () => {
test("should verify that the iframe got created with correct URL", async ({
page,
getActionFiredDetails,
Expand Down

0 comments on commit 2272da5

Please sign in to comment.