2022-05-14 03:02:10 +00:00
|
|
|
import { expect } from "@playwright/test";
|
2023-08-11 18:56:27 +00:00
|
|
|
|
|
|
|
import { randomString } from "@calcom/lib/random";
|
2021-10-13 13:26:56 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
import { test } from "./lib/fixtures";
|
2022-03-24 17:32:28 +00:00
|
|
|
import {
|
2022-04-06 17:20:30 +00:00
|
|
|
bookFirstEvent,
|
2022-10-27 09:34:34 +00:00
|
|
|
bookOptinEvent,
|
2022-04-06 17:20:30 +00:00
|
|
|
bookTimeSlot,
|
2023-08-23 09:08:14 +00:00
|
|
|
expectEmailsToHaveSubject,
|
2022-03-24 17:32:28 +00:00
|
|
|
selectFirstAvailableTimeSlotNextMonth,
|
2023-05-22 23:15:06 +00:00
|
|
|
testEmail,
|
|
|
|
testName,
|
2022-03-24 17:32:28 +00:00
|
|
|
} from "./lib/testUtils";
|
|
|
|
|
2023-08-11 18:56:27 +00:00
|
|
|
const freeUserObj = { name: `Free-user-${randomString(3)}` };
|
2022-05-11 18:03:22 +00:00
|
|
|
test.describe.configure({ mode: "parallel" });
|
2023-08-11 18:56:27 +00:00
|
|
|
test.afterEach(async ({ users }) => {
|
|
|
|
await users.deleteAll();
|
|
|
|
});
|
2022-05-11 18:03:22 +00:00
|
|
|
|
2023-07-11 11:31:55 +00:00
|
|
|
test.describe("free user", () => {
|
2022-05-14 03:02:10 +00:00
|
|
|
test.beforeEach(async ({ page, users }) => {
|
2023-08-11 18:56:27 +00:00
|
|
|
const free = await users.create(freeUserObj);
|
2022-05-14 03:02:10 +00:00
|
|
|
await page.goto(`/${free.username}`);
|
2021-12-15 16:25:49 +00:00
|
|
|
});
|
2022-03-07 17:55:24 +00:00
|
|
|
|
2023-08-11 18:56:27 +00:00
|
|
|
test("cannot book same slot multiple times", async ({ page, users, emails }) => {
|
|
|
|
const [user] = users.get();
|
|
|
|
const bookerObj = { email: `testEmail-${randomString(4)}@example.com`, name: "testBooker" };
|
2022-03-07 17:55:24 +00:00
|
|
|
// Click first event type
|
|
|
|
await page.click('[data-testid="event-type-link"]');
|
2022-03-08 22:40:31 +00:00
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
2022-03-07 17:55:24 +00:00
|
|
|
|
2023-08-11 18:56:27 +00:00
|
|
|
await bookTimeSlot(page, bookerObj);
|
2023-07-11 15:11:08 +00:00
|
|
|
|
2022-03-07 17:55:24 +00:00
|
|
|
// save booking url
|
|
|
|
const bookingUrl: string = page.url();
|
|
|
|
|
|
|
|
// Make sure we're navigated to the success page
|
2022-05-11 16:46:52 +00:00
|
|
|
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
2023-08-11 18:56:27 +00:00
|
|
|
const { title: eventTitle } = await user.getFirstEventAsOwner();
|
2022-03-07 17:55:24 +00:00
|
|
|
|
2023-08-23 09:08:14 +00:00
|
|
|
await expectEmailsToHaveSubject({
|
|
|
|
emails,
|
|
|
|
organizer: user,
|
|
|
|
booker: bookerObj,
|
|
|
|
eventTitle,
|
|
|
|
});
|
2022-03-07 17:55:24 +00:00
|
|
|
await page.goto(bookingUrl);
|
|
|
|
|
|
|
|
// book same time spot again
|
2022-03-23 22:00:30 +00:00
|
|
|
await bookTimeSlot(page);
|
2022-03-07 17:55:24 +00:00
|
|
|
|
2023-07-11 15:11:08 +00:00
|
|
|
await expect(page.locator("[data-testid=booking-fail]")).toBeVisible({ timeout: 1000 });
|
2022-03-07 17:55:24 +00:00
|
|
|
});
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|
|
|
|
|
2023-07-11 11:31:55 +00:00
|
|
|
test.describe("pro user", () => {
|
2022-05-14 03:02:10 +00:00
|
|
|
test.beforeEach(async ({ page, users }) => {
|
|
|
|
const pro = await users.create();
|
|
|
|
await page.goto(`/${pro.username}`);
|
2021-12-15 16:25:49 +00:00
|
|
|
});
|
2022-03-07 17:55:24 +00:00
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
test("pro user's page has at least 2 visible events", async ({ page }) => {
|
2022-05-11 20:36:38 +00:00
|
|
|
const $eventTypes = page.locator("[data-testid=event-types] > *");
|
2022-03-17 19:36:11 +00:00
|
|
|
expect(await $eventTypes.count()).toBeGreaterThanOrEqual(2);
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
test("book an event first day in next month", async ({ page }) => {
|
2022-05-12 03:07:22 +00:00
|
|
|
await bookFirstEvent(page);
|
2021-11-15 15:03:04 +00:00
|
|
|
});
|
2022-05-12 03:07:22 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("can reschedule a booking", async ({ page, users, bookings }) => {
|
|
|
|
const [pro] = users.get();
|
|
|
|
const [eventType] = pro.eventTypes;
|
|
|
|
await bookings.create(pro.id, pro.username, eventType.id);
|
2022-03-24 17:32:28 +00:00
|
|
|
|
2023-06-06 18:02:32 +00:00
|
|
|
await pro.apiLogin();
|
2022-03-24 17:32:28 +00:00
|
|
|
await page.goto("/bookings/upcoming");
|
2022-11-26 13:41:24 +00:00
|
|
|
await page.waitForSelector('[data-testid="bookings"]');
|
2022-05-27 23:27:41 +00:00
|
|
|
await page.locator('[data-testid="edit_booking"]').nth(0).click();
|
|
|
|
await page.locator('[data-testid="reschedule"]').click();
|
2023-05-02 16:58:39 +00:00
|
|
|
await page.waitForURL((url) => {
|
|
|
|
const bookingId = url.searchParams.get("rescheduleUid");
|
|
|
|
return !!bookingId;
|
2022-03-24 17:32:28 +00:00
|
|
|
});
|
2023-07-11 15:11:08 +00:00
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
2022-03-24 17:32:28 +00:00
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
2023-05-02 16:58:39 +00:00
|
|
|
await page.waitForURL((url) => {
|
|
|
|
return url.pathname.startsWith("/booking");
|
2022-03-24 17:32:28 +00:00
|
|
|
});
|
|
|
|
});
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2023-05-03 15:30:26 +00:00
|
|
|
test("Can cancel the recently created booking and rebook the same timeslot", async ({
|
|
|
|
page,
|
|
|
|
users,
|
|
|
|
}, testInfo) => {
|
|
|
|
// Because it tests the entire booking flow + the cancellation + rebooking
|
|
|
|
test.setTimeout(testInfo.timeout * 3);
|
2022-03-24 17:32:28 +00:00
|
|
|
await bookFirstEvent(page);
|
2023-05-22 23:15:06 +00:00
|
|
|
await expect(page.locator(`[data-testid="attendee-email-${testEmail}"]`)).toHaveText(testEmail);
|
|
|
|
await expect(page.locator(`[data-testid="attendee-name-${testName}"]`)).toHaveText(testName);
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
const [pro] = users.get();
|
2023-06-06 18:02:32 +00:00
|
|
|
await pro.apiLogin();
|
2022-05-14 03:02:10 +00:00
|
|
|
|
2022-03-24 17:32:28 +00:00
|
|
|
await page.goto("/bookings/upcoming");
|
2023-06-10 03:47:50 +00:00
|
|
|
await page.locator('[data-testid="cancel"]').click();
|
2023-05-02 16:58:39 +00:00
|
|
|
await page.waitForURL((url) => {
|
2023-05-03 15:30:26 +00:00
|
|
|
return url.pathname.startsWith("/booking/");
|
2022-03-24 17:32:28 +00:00
|
|
|
});
|
2023-06-10 03:47:50 +00:00
|
|
|
await page.locator('[data-testid="confirm_cancel"]').click();
|
2022-11-25 14:49:59 +00:00
|
|
|
|
2023-06-10 03:47:50 +00:00
|
|
|
const cancelledHeadline = page.locator('[data-testid="cancelled-headline"]');
|
|
|
|
await expect(cancelledHeadline).toBeVisible();
|
2023-05-22 23:15:06 +00:00
|
|
|
|
|
|
|
await expect(page.locator(`[data-testid="attendee-email-${testEmail}"]`)).toHaveText(testEmail);
|
|
|
|
await expect(page.locator(`[data-testid="attendee-name-${testName}"]`)).toHaveText(testName);
|
2022-11-25 14:49:59 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await page.goto(`/${pro.username}`);
|
2022-04-14 15:01:38 +00:00
|
|
|
await bookFirstEvent(page);
|
2022-03-24 17:32:28 +00:00
|
|
|
});
|
2022-10-27 09:34:34 +00:00
|
|
|
|
|
|
|
test("can book an event that requires confirmation and then that booking can be accepted by organizer", async ({
|
|
|
|
page,
|
|
|
|
users,
|
|
|
|
}) => {
|
|
|
|
await bookOptinEvent(page);
|
|
|
|
const [pro] = users.get();
|
2023-06-06 18:02:32 +00:00
|
|
|
await pro.apiLogin();
|
2022-10-27 09:34:34 +00:00
|
|
|
|
|
|
|
await page.goto("/bookings/unconfirmed");
|
|
|
|
await Promise.all([
|
|
|
|
page.click('[data-testid="confirm"]'),
|
2023-05-05 16:19:10 +00:00
|
|
|
page.waitForResponse((response) => response.url().includes("/api/trpc/bookings/confirm")),
|
2022-10-27 09:34:34 +00:00
|
|
|
]);
|
|
|
|
// This is the only booking in there that needed confirmation and now it should be empty screen
|
|
|
|
await expect(page.locator('[data-testid="empty-screen"]')).toBeVisible();
|
|
|
|
});
|
2023-03-17 07:03:54 +00:00
|
|
|
|
|
|
|
test("can book with multiple guests", async ({ page, users }) => {
|
|
|
|
const additionalGuests = ["test@gmail.com", "test2@gmail.com"];
|
|
|
|
|
|
|
|
await page.click('[data-testid="event-type-link"]');
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
await page.fill('[name="name"]', "test1234");
|
|
|
|
await page.fill('[name="email"]', "test1234@example.com");
|
|
|
|
await page.locator('[data-testid="add-guests"]').click();
|
|
|
|
|
|
|
|
await page.locator('input[type="email"]').nth(1).fill(additionalGuests[0]);
|
|
|
|
await page.locator('[data-testid="add-another-guest"]').click();
|
|
|
|
await page.locator('input[type="email"]').nth(2).fill(additionalGuests[1]);
|
|
|
|
|
|
|
|
await page.locator('[data-testid="confirm-book-button"]').click();
|
|
|
|
|
|
|
|
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
|
|
|
|
2023-08-26 00:43:10 +00:00
|
|
|
const promises = additionalGuests.map(async (email) => {
|
2023-05-22 23:15:06 +00:00
|
|
|
await expect(page.locator(`[data-testid="attendee-email-${email}"]`)).toHaveText(email);
|
2023-03-17 07:03:54 +00:00
|
|
|
});
|
2023-08-26 00:43:10 +00:00
|
|
|
await Promise.all(promises);
|
2023-03-17 07:03:54 +00:00
|
|
|
});
|
2023-07-11 15:11:08 +00:00
|
|
|
|
|
|
|
test("Time slots should be reserved when selected", async ({ context, page }) => {
|
|
|
|
await page.click('[data-testid="event-type-link"]');
|
|
|
|
|
|
|
|
const initialUrl = page.url();
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
const pageTwo = await context.newPage();
|
|
|
|
await pageTwo.goto(initialUrl);
|
|
|
|
await pageTwo.waitForURL(initialUrl);
|
|
|
|
|
|
|
|
await pageTwo.waitForSelector('[data-testid="event-type-link"]');
|
|
|
|
const eventTypeLink = pageTwo.locator('[data-testid="event-type-link"]').first();
|
|
|
|
await eventTypeLink.click();
|
|
|
|
|
|
|
|
await pageTwo.waitForLoadState("networkidle");
|
|
|
|
await pageTwo.locator('[data-testid="incrementMonth"]').waitFor();
|
|
|
|
await pageTwo.click('[data-testid="incrementMonth"]');
|
|
|
|
await pageTwo.waitForLoadState("networkidle");
|
|
|
|
await pageTwo.locator('[data-testid="day"][data-disabled="false"]').nth(0).waitFor();
|
|
|
|
await pageTwo.locator('[data-testid="day"][data-disabled="false"]').nth(0).click();
|
|
|
|
|
|
|
|
// 9:30 should be the first available time slot
|
|
|
|
await pageTwo.locator('[data-testid="time"]').nth(0).waitFor();
|
|
|
|
const firstSlotAvailable = pageTwo.locator('[data-testid="time"]').nth(0);
|
|
|
|
// Find text inside the element
|
|
|
|
const firstSlotAvailableText = await firstSlotAvailable.innerText();
|
|
|
|
expect(firstSlotAvailableText).toContain("9:30");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Time slots are not reserved when going back via Cancel button on Event Form", async ({
|
|
|
|
context,
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const initialUrl = page.url();
|
|
|
|
await page.waitForSelector('[data-testid="event-type-link"]');
|
|
|
|
const eventTypeLink = page.locator('[data-testid="event-type-link"]').first();
|
|
|
|
await eventTypeLink.click();
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
const pageTwo = await context.newPage();
|
|
|
|
await pageTwo.goto(initialUrl);
|
|
|
|
await pageTwo.waitForURL(initialUrl);
|
|
|
|
|
|
|
|
await pageTwo.waitForSelector('[data-testid="event-type-link"]');
|
|
|
|
const eventTypeLinkTwo = pageTwo.locator('[data-testid="event-type-link"]').first();
|
|
|
|
await eventTypeLinkTwo.click();
|
|
|
|
|
|
|
|
await page.locator('[data-testid="back"]').waitFor();
|
|
|
|
await page.click('[data-testid="back"]');
|
|
|
|
|
|
|
|
await pageTwo.waitForLoadState("networkidle");
|
|
|
|
await pageTwo.locator('[data-testid="incrementMonth"]').waitFor();
|
|
|
|
await pageTwo.click('[data-testid="incrementMonth"]');
|
|
|
|
await pageTwo.waitForLoadState("networkidle");
|
|
|
|
await pageTwo.locator('[data-testid="day"][data-disabled="false"]').nth(0).waitFor();
|
|
|
|
await pageTwo.locator('[data-testid="day"][data-disabled="false"]').nth(0).click();
|
|
|
|
|
|
|
|
await pageTwo.locator('[data-testid="time"]').nth(0).waitFor();
|
|
|
|
const firstSlotAvailable = pageTwo.locator('[data-testid="time"]').nth(0);
|
|
|
|
|
|
|
|
// Find text inside the element
|
|
|
|
const firstSlotAvailableText = await firstSlotAvailable.innerText();
|
|
|
|
expect(firstSlotAvailableText).toContain("9:00");
|
|
|
|
});
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|
2023-08-02 06:40:33 +00:00
|
|
|
|
|
|
|
test.describe("prefill", () => {
|
|
|
|
test("logged in", async ({ page, users }) => {
|
|
|
|
const prefill = await users.create({ name: "Prefill User" });
|
|
|
|
await prefill.apiLogin();
|
|
|
|
await page.goto("/pro/30min");
|
|
|
|
|
|
|
|
await test.step("from session", async () => {
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
await expect(page.locator('[name="name"]')).toHaveValue(prefill.name || "");
|
|
|
|
await expect(page.locator('[name="email"]')).toHaveValue(prefill.email);
|
|
|
|
});
|
|
|
|
|
|
|
|
await test.step("from query params", async () => {
|
|
|
|
const url = new URL(page.url());
|
|
|
|
url.searchParams.set("name", testName);
|
|
|
|
url.searchParams.set("email", testEmail);
|
|
|
|
await page.goto(url.toString());
|
|
|
|
|
|
|
|
await expect(page.locator('[name="name"]')).toHaveValue(testName);
|
|
|
|
await expect(page.locator('[name="email"]')).toHaveValue(testEmail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("logged out", async ({ page, users }) => {
|
|
|
|
await page.goto("/pro/30min");
|
|
|
|
|
|
|
|
await test.step("from query params", async () => {
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
const url = new URL(page.url());
|
|
|
|
url.searchParams.set("name", testName);
|
|
|
|
url.searchParams.set("email", testEmail);
|
|
|
|
await page.goto(url.toString());
|
|
|
|
|
|
|
|
await expect(page.locator('[name="name"]')).toHaveValue(testName);
|
|
|
|
await expect(page.locator('[name="email"]')).toHaveValue(testEmail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|