2022-03-23 22:00:30 +00:00
|
|
|
import { expect, Page, test } from "@playwright/test";
|
2021-10-13 13:26:56 +00:00
|
|
|
|
2022-03-17 19:36:11 +00:00
|
|
|
import { deleteAllBookingsByEmail } from "./lib/teardown";
|
2022-03-08 22:40:31 +00:00
|
|
|
import { selectFirstAvailableTimeSlotNextMonth, todo } from "./lib/testUtils";
|
2021-10-13 13:26:56 +00:00
|
|
|
|
2022-03-23 22:00:30 +00:00
|
|
|
const bookTimeSlot = async (page: Page) => {
|
|
|
|
// --- fill form
|
|
|
|
await page.fill('[name="name"]', "Test Testson");
|
|
|
|
await page.fill('[name="email"]', "test@example.com");
|
|
|
|
await page.press('[name="email"]', "Enter");
|
|
|
|
};
|
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
test.describe("free user", () => {
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
await page.goto("/free");
|
|
|
|
});
|
2022-03-07 17:55:24 +00:00
|
|
|
|
|
|
|
test.afterEach(async () => {
|
|
|
|
// delete test bookings
|
2022-03-17 19:36:11 +00:00
|
|
|
await deleteAllBookingsByEmail("free@example.com");
|
2022-03-07 17:55:24 +00:00
|
|
|
});
|
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
test("only one visible event", async ({ page }) => {
|
|
|
|
await expect(page.locator(`[href="/free/30min"]`)).toBeVisible();
|
|
|
|
await expect(page.locator(`[href="/free/60min"]`)).not.toBeVisible();
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|
|
|
|
|
2022-03-07 17:55:24 +00:00
|
|
|
test("cannot book same slot multiple times", async ({ page }) => {
|
|
|
|
// 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
|
|
|
|
|
|
|
// Navigate to book page
|
|
|
|
await page.waitForNavigation({
|
|
|
|
url(url) {
|
|
|
|
return url.pathname.endsWith("/book");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// save booking url
|
|
|
|
const bookingUrl: string = page.url();
|
|
|
|
|
|
|
|
// book same time spot twice
|
2022-03-23 22:00:30 +00:00
|
|
|
await bookTimeSlot(page);
|
2022-03-07 17:55:24 +00:00
|
|
|
|
|
|
|
// Make sure we're navigated to the success page
|
|
|
|
await page.waitForNavigation({
|
|
|
|
url(url) {
|
|
|
|
return url.pathname.endsWith("/success");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// return to same time spot booking page
|
|
|
|
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
|
|
|
|
|
|
|
// check for error message
|
|
|
|
await expect(page.locator("[data-testid=booking-fail]")).toBeVisible();
|
|
|
|
});
|
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
todo("`/free/30min` is bookable");
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
todo("`/free/60min` is not bookable");
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
test.describe("pro user", () => {
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
|
|
await page.goto("/pro");
|
|
|
|
});
|
2021-10-13 13:26:56 +00:00
|
|
|
|
2022-03-17 19:36:11 +00:00
|
|
|
test.afterAll(async () => {
|
2022-03-07 17:55:24 +00:00
|
|
|
// delete test bookings
|
2022-03-17 19:36:11 +00:00
|
|
|
await deleteAllBookingsByEmail("pro@example.com");
|
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-03-17 19:36:11 +00:00
|
|
|
// await page.pause();
|
|
|
|
const $eventTypes = await page.locator("[data-testid=event-types] > *");
|
|
|
|
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 }) => {
|
2021-11-15 15:03:04 +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-23 22:00:30 +00:00
|
|
|
await bookTimeSlot(page);
|
2021-11-15 15:03:04 +00:00
|
|
|
|
|
|
|
// Make sure we're navigated to the success page
|
|
|
|
await page.waitForNavigation({
|
|
|
|
url(url) {
|
|
|
|
return url.pathname.endsWith("/success");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
todo("Can reschedule the recently created booking");
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
todo("Can cancel the recently created booking");
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|