2022-04-06 17:20:30 +00:00
|
|
|
import { expect, 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-24 17:32:28 +00:00
|
|
|
import {
|
2022-04-06 17:20:30 +00:00
|
|
|
bookFirstEvent,
|
|
|
|
bookTimeSlot,
|
2022-03-24 17:32:28 +00:00
|
|
|
selectFirstAvailableTimeSlotNextMonth,
|
|
|
|
selectSecondAvailableTimeSlotNextMonth,
|
|
|
|
todo,
|
|
|
|
} from "./lib/testUtils";
|
|
|
|
|
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
|
2022-05-11 16:46:52 +00:00
|
|
|
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
2022-03-07 17:55:24 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
});
|
|
|
|
|
2022-03-24 17:32:28 +00:00
|
|
|
// Why do we need this test. The previous test is testing /30min booking only ?
|
2021-12-15 16:25:49 +00:00
|
|
|
todo("`/free/30min` is bookable");
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2022-03-24 17:32:28 +00:00
|
|
|
test("`/free/60min` is not bookable", async ({ page }) => {
|
|
|
|
// Not available in listing
|
|
|
|
await expect(page.locator('[href="/free/60min"]')).toHaveCount(0);
|
|
|
|
|
|
|
|
await page.goto("/free/60min");
|
|
|
|
// Not available on a direct visit to event type page
|
|
|
|
await expect(page.locator('[data-testid="404-page"]')).toBeVisible();
|
|
|
|
});
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
test.describe("pro user", () => {
|
2022-03-24 17:32:28 +00:00
|
|
|
test.use({ storageState: "playwright/artifacts/proStorageState.json" });
|
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
test.beforeEach(async ({ page }) => {
|
2022-04-07 07:34:19 +00:00
|
|
|
await deleteAllBookingsByEmail("pro@example.com");
|
2021-12-15 16:25:49 +00:00
|
|
|
await page.goto("/pro");
|
|
|
|
});
|
2021-10-13 13:26:56 +00:00
|
|
|
|
2022-04-07 07:34:19 +00:00
|
|
|
test.afterEach(async () => {
|
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
|
2022-05-11 16:46:52 +00:00
|
|
|
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
2021-11-15 15:03:04 +00:00
|
|
|
});
|
2022-03-24 17:32:28 +00:00
|
|
|
test("can reschedule a booking", async ({ page }) => {
|
|
|
|
await bookFirstEvent(page);
|
|
|
|
|
|
|
|
await page.goto("/bookings/upcoming");
|
|
|
|
await page.locator('[data-testid="reschedule"]').click();
|
2022-04-14 21:25:24 +00:00
|
|
|
await page.locator('[data-testid="edit"]').click();
|
2022-03-24 17:32:28 +00:00
|
|
|
await page.waitForNavigation({
|
|
|
|
url: (url) => {
|
|
|
|
const bookingId = url.searchParams.get("rescheduleUid");
|
|
|
|
return !!bookingId;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await selectSecondAvailableTimeSlotNextMonth(page);
|
|
|
|
// --- fill form
|
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
|
|
|
await page.waitForNavigation({
|
|
|
|
url(url) {
|
|
|
|
return url.pathname === "/success" && url.searchParams.get("reschedule") === "true";
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2022-04-14 15:01:38 +00:00
|
|
|
test("Can cancel the recently created booking and rebook the same timeslot", async ({ page }) => {
|
2022-03-24 17:32:28 +00:00
|
|
|
await bookFirstEvent(page);
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2022-03-24 17:32:28 +00:00
|
|
|
await page.goto("/bookings/upcoming");
|
2022-04-05 08:05:40 +00:00
|
|
|
await page.locator('[data-testid="cancel"]').first().click();
|
2022-03-24 17:32:28 +00:00
|
|
|
await page.waitForNavigation({
|
|
|
|
url: (url) => {
|
|
|
|
return url.pathname.startsWith("/cancel");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
// --- fill form
|
|
|
|
await page.locator('[data-testid="cancel"]').click();
|
|
|
|
await page.waitForNavigation({
|
|
|
|
url(url) {
|
|
|
|
return url.pathname === "/cancel/success";
|
|
|
|
},
|
|
|
|
});
|
2022-04-14 15:01:38 +00:00
|
|
|
await page.goto("/pro");
|
|
|
|
await bookFirstEvent(page);
|
2022-03-24 17:32:28 +00:00
|
|
|
});
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|