2023-02-16 22:39:57 +00:00
|
|
|
import type { Page } from "@playwright/test";
|
|
|
|
import { expect } from "@playwright/test";
|
2022-09-02 02:00:48 +00:00
|
|
|
|
|
|
|
import { test } from "./lib/fixtures";
|
2022-05-05 14:29:49 +00:00
|
|
|
|
2022-09-19 09:47:46 +00:00
|
|
|
function chooseEmbedType(page: Page, embedType: string) {
|
|
|
|
page.locator(`[data-testid=${embedType}]`).click();
|
2022-05-05 14:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function gotToPreviewTab(page: Page) {
|
2022-05-14 03:02:10 +00:00
|
|
|
// To prevent early timeouts
|
2022-05-17 19:31:49 +00:00
|
|
|
// eslint-disable-next-line playwright/no-wait-for-timeout
|
2022-05-14 03:02:10 +00:00
|
|
|
await page.waitForTimeout(1000);
|
2022-05-05 14:29:49 +00:00
|
|
|
await page.locator("[data-testid=embed-tabs]").locator("text=Preview").click();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function clickEmbedButton(page: Page) {
|
2022-08-13 11:04:57 +00:00
|
|
|
const embedButton = page.locator("[data-testid=embed]");
|
|
|
|
const embedUrl = await embedButton.getAttribute("data-test-embed-url");
|
2022-05-05 14:29:49 +00:00
|
|
|
embedButton.click();
|
2022-08-17 17:38:21 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
|
return embedUrl!;
|
2022-05-05 14:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function clickFirstEventTypeEmbedButton(page: Page) {
|
|
|
|
const menu = page.locator("[data-testid*=event-type-options]").first();
|
|
|
|
await menu.click();
|
2022-08-13 11:04:57 +00:00
|
|
|
const embedUrl = await clickEmbedButton(page);
|
|
|
|
return embedUrl;
|
2022-05-05 14:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function expectToBeNavigatingToEmbedTypesDialog(
|
|
|
|
page: Page,
|
2022-08-13 11:04:57 +00:00
|
|
|
{ embedUrl, basePage }: { embedUrl: string | null; basePage: string }
|
2022-05-05 14:29:49 +00:00
|
|
|
) {
|
2022-08-13 11:04:57 +00:00
|
|
|
if (!embedUrl) {
|
|
|
|
throw new Error("Couldn't find embedUrl");
|
2022-05-05 14:29:49 +00:00
|
|
|
}
|
2023-05-02 16:58:39 +00:00
|
|
|
await page.waitForURL((url) => {
|
|
|
|
return (
|
|
|
|
url.pathname === basePage &&
|
|
|
|
url.searchParams.get("dialog") === "embed" &&
|
|
|
|
url.searchParams.get("embedUrl") === embedUrl
|
|
|
|
);
|
2022-05-05 14:29:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function expectToBeNavigatingToEmbedCodeAndPreviewDialog(
|
|
|
|
page: Page,
|
2022-08-13 11:04:57 +00:00
|
|
|
{ embedUrl, embedType, basePage }: { embedUrl: string | null; embedType: string; basePage: string }
|
2022-05-05 14:29:49 +00:00
|
|
|
) {
|
2022-08-13 11:04:57 +00:00
|
|
|
if (!embedUrl) {
|
|
|
|
throw new Error("Couldn't find embedUrl");
|
2022-05-05 14:29:49 +00:00
|
|
|
}
|
2023-05-02 16:58:39 +00:00
|
|
|
await page.waitForURL((url) => {
|
|
|
|
return (
|
|
|
|
url.pathname === basePage &&
|
|
|
|
url.searchParams.get("dialog") === "embed" &&
|
|
|
|
url.searchParams.get("embedUrl") === embedUrl &&
|
|
|
|
url.searchParams.get("embedType") === embedType &&
|
|
|
|
url.searchParams.get("embedTabName") === "embed-code"
|
|
|
|
);
|
2022-05-05 14:29:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function expectToContainValidCode(page: Page, { embedType }: { embedType: string }) {
|
|
|
|
const embedCode = await page.locator("[data-testid=embed-code]").inputValue();
|
|
|
|
expect(embedCode.includes("(function (C, A, L)")).toBe(true);
|
|
|
|
expect(embedCode.includes(`Cal ${embedType} embed code begins`)).toBe(true);
|
|
|
|
return {
|
|
|
|
message: () => `passed`,
|
|
|
|
pass: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async function expectToContainValidPreviewIframe(
|
|
|
|
page: Page,
|
|
|
|
{ embedType, calLink }: { embedType: string; calLink: string }
|
|
|
|
) {
|
|
|
|
expect(await page.locator("[data-testid=embed-preview]").getAttribute("src")).toContain(
|
|
|
|
`/preview.html?embedType=${embedType}&calLink=${calLink}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-05-11 17:12:58 +00:00
|
|
|
test.describe.configure({ mode: "parallel" });
|
|
|
|
|
2023-03-01 20:18:51 +00:00
|
|
|
test.afterEach(({ users }) => users.deleteAll());
|
|
|
|
|
2022-05-05 14:29:49 +00:00
|
|
|
test.describe("Embed Code Generator Tests", () => {
|
2022-09-02 02:00:48 +00:00
|
|
|
test.beforeEach(async ({ users }) => {
|
|
|
|
const pro = await users.create();
|
|
|
|
await pro.login();
|
|
|
|
});
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
test.describe("Event Types Page", () => {
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
await page.goto("/event-types");
|
|
|
|
});
|
|
|
|
|
2022-09-02 02:00:48 +00:00
|
|
|
test("open Embed Dialog and choose Inline for First Event Type", async ({ page, users }) => {
|
|
|
|
const [pro] = users.get();
|
2022-08-13 11:04:57 +00:00
|
|
|
const embedUrl = await clickFirstEventTypeEmbedButton(page);
|
2022-05-05 14:29:49 +00:00
|
|
|
await expectToBeNavigatingToEmbedTypesDialog(page, {
|
2022-08-13 11:04:57 +00:00
|
|
|
embedUrl,
|
2022-05-05 14:29:49 +00:00
|
|
|
basePage: "/event-types",
|
|
|
|
});
|
|
|
|
|
2022-09-19 09:47:46 +00:00
|
|
|
chooseEmbedType(page, "inline");
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await expectToBeNavigatingToEmbedCodeAndPreviewDialog(page, {
|
2022-08-13 11:04:57 +00:00
|
|
|
embedUrl,
|
2022-05-05 14:29:49 +00:00
|
|
|
embedType: "inline",
|
|
|
|
basePage: "/event-types",
|
|
|
|
});
|
|
|
|
|
2022-09-19 09:47:46 +00:00
|
|
|
await expectToContainValidCode(page, { embedType: "inline" });
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await gotToPreviewTab(page);
|
|
|
|
|
2022-09-02 02:00:48 +00:00
|
|
|
await expectToContainValidPreviewIframe(page, {
|
|
|
|
embedType: "inline",
|
|
|
|
calLink: `${pro.username}/30-min`,
|
2022-09-19 09:47:46 +00:00
|
|
|
});
|
2022-05-05 14:29:49 +00:00
|
|
|
});
|
|
|
|
|
2022-09-02 02:00:48 +00:00
|
|
|
test("open Embed Dialog and choose floating-popup for First Event Type", async ({ page, users }) => {
|
|
|
|
const [pro] = users.get();
|
2022-08-13 11:04:57 +00:00
|
|
|
const embedUrl = await clickFirstEventTypeEmbedButton(page);
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await expectToBeNavigatingToEmbedTypesDialog(page, {
|
2022-08-13 11:04:57 +00:00
|
|
|
embedUrl,
|
2022-05-05 14:29:49 +00:00
|
|
|
basePage: "/event-types",
|
|
|
|
});
|
|
|
|
|
2022-09-19 09:47:46 +00:00
|
|
|
chooseEmbedType(page, "floating-popup");
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await expectToBeNavigatingToEmbedCodeAndPreviewDialog(page, {
|
2022-08-13 11:04:57 +00:00
|
|
|
embedUrl,
|
2022-05-05 14:29:49 +00:00
|
|
|
embedType: "floating-popup",
|
|
|
|
basePage: "/event-types",
|
|
|
|
});
|
2022-09-19 09:47:46 +00:00
|
|
|
await expectToContainValidCode(page, { embedType: "floating-popup" });
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await gotToPreviewTab(page);
|
2022-09-02 02:00:48 +00:00
|
|
|
await expectToContainValidPreviewIframe(page, {
|
|
|
|
embedType: "floating-popup",
|
|
|
|
calLink: `${pro.username}/30-min`,
|
2022-09-19 09:47:46 +00:00
|
|
|
});
|
2022-05-05 14:29:49 +00:00
|
|
|
});
|
|
|
|
|
2022-09-02 02:00:48 +00:00
|
|
|
test("open Embed Dialog and choose element-click for First Event Type", async ({ page, users }) => {
|
|
|
|
const [pro] = users.get();
|
2022-08-13 11:04:57 +00:00
|
|
|
const embedUrl = await clickFirstEventTypeEmbedButton(page);
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await expectToBeNavigatingToEmbedTypesDialog(page, {
|
2022-08-13 11:04:57 +00:00
|
|
|
embedUrl,
|
2022-05-05 14:29:49 +00:00
|
|
|
basePage: "/event-types",
|
|
|
|
});
|
|
|
|
|
2022-09-19 09:47:46 +00:00
|
|
|
chooseEmbedType(page, "element-click");
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await expectToBeNavigatingToEmbedCodeAndPreviewDialog(page, {
|
2022-08-13 11:04:57 +00:00
|
|
|
embedUrl,
|
2022-05-05 14:29:49 +00:00
|
|
|
embedType: "element-click",
|
|
|
|
basePage: "/event-types",
|
|
|
|
});
|
2022-09-19 09:47:46 +00:00
|
|
|
await expectToContainValidCode(page, { embedType: "element-click" });
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await gotToPreviewTab(page);
|
2022-09-02 02:00:48 +00:00
|
|
|
await expectToContainValidPreviewIframe(page, {
|
|
|
|
embedType: "element-click",
|
|
|
|
calLink: `${pro.username}/30-min`,
|
2022-09-19 09:47:46 +00:00
|
|
|
});
|
2022-05-05 14:29:49 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test.describe("Event Type Edit Page", () => {
|
|
|
|
test.beforeEach(async ({ page }) => {
|
2022-08-17 17:38:21 +00:00
|
|
|
await page.goto(`/event-types`);
|
|
|
|
await Promise.all([
|
2023-05-30 13:52:07 +00:00
|
|
|
page.locator('a[href*="/event-types/"]').first().click(),
|
2023-05-02 16:58:39 +00:00
|
|
|
page.waitForURL((url) => url.pathname.startsWith("/event-types/")),
|
2022-08-17 17:38:21 +00:00
|
|
|
]);
|
2022-05-05 14:29:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test("open Embed Dialog for the Event Type", async ({ page }) => {
|
2022-08-17 17:38:21 +00:00
|
|
|
const basePage = new URL(page.url()).pathname;
|
2022-08-13 11:04:57 +00:00
|
|
|
const embedUrl = await clickEmbedButton(page);
|
2022-05-05 14:29:49 +00:00
|
|
|
await expectToBeNavigatingToEmbedTypesDialog(page, {
|
2022-08-13 11:04:57 +00:00
|
|
|
embedUrl,
|
2022-08-17 17:38:21 +00:00
|
|
|
basePage,
|
2022-05-05 14:29:49 +00:00
|
|
|
});
|
|
|
|
|
2022-09-19 09:47:46 +00:00
|
|
|
chooseEmbedType(page, "inline");
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await expectToBeNavigatingToEmbedCodeAndPreviewDialog(page, {
|
2022-08-13 11:04:57 +00:00
|
|
|
embedUrl,
|
2022-08-17 17:38:21 +00:00
|
|
|
basePage,
|
2022-05-05 14:29:49 +00:00
|
|
|
embedType: "inline",
|
|
|
|
});
|
|
|
|
|
2022-09-19 09:47:46 +00:00
|
|
|
await expectToContainValidCode(page, {
|
2022-05-05 14:29:49 +00:00
|
|
|
embedType: "inline",
|
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await gotToPreviewTab(page);
|
2022-05-05 14:29:49 +00:00
|
|
|
|
|
|
|
await expectToContainValidPreviewIframe(page, {
|
|
|
|
embedType: "inline",
|
2022-08-17 17:38:21 +00:00
|
|
|
calLink: decodeURIComponent(embedUrl),
|
2022-09-19 09:47:46 +00:00
|
|
|
});
|
2022-05-05 14:29:49 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|