2022-05-14 03:02:10 +00:00
|
|
|
import { expect } from "@playwright/test";
|
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,
|
|
|
|
bookTimeSlot,
|
2022-03-24 17:32:28 +00:00
|
|
|
selectFirstAvailableTimeSlotNextMonth,
|
|
|
|
selectSecondAvailableTimeSlotNextMonth,
|
|
|
|
} from "./lib/testUtils";
|
|
|
|
|
2022-05-11 18:03:22 +00:00
|
|
|
test.describe.configure({ mode: "parallel" });
|
|
|
|
|
2021-12-15 16:25:49 +00:00
|
|
|
test.describe("free user", () => {
|
2022-05-14 03:02:10 +00:00
|
|
|
test.beforeEach(async ({ page, users }) => {
|
|
|
|
const free = await users.create({ plan: "FREE" });
|
|
|
|
await page.goto(`/${free.username}`);
|
2021-12-15 16:25:49 +00:00
|
|
|
});
|
2022-05-14 03:02:10 +00:00
|
|
|
test.afterEach(async ({ users }) => {
|
|
|
|
await users.deleteAll();
|
2022-03-07 17:55:24 +00:00
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("only one visible event", async ({ page, users }) => {
|
|
|
|
const [free] = users.get();
|
|
|
|
await expect(page.locator(`[href="/${free.username}/${free.eventTypes[0].slug}"]`)).toBeVisible();
|
|
|
|
await expect(page.locator(`[href="/${free.username}/${free.eventTypes[1].slug}"]`)).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-05-14 03:02:10 +00:00
|
|
|
test("Second event type is not bookable", async ({ page, users }) => {
|
|
|
|
const [free] = users.get();
|
2022-03-24 17:32:28 +00:00
|
|
|
// Not available in listing
|
2022-05-14 03:02:10 +00:00
|
|
|
await expect(page.locator(`[href="/${free.username}/${free.eventTypes[1].slug}"]`)).toHaveCount(0);
|
2022-03-24 17:32:28 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await page.goto(`/${free.username}/${free.eventTypes[1].slug}`);
|
2022-03-24 17:32:28 +00:00
|
|
|
// 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-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-05-14 03:02:10 +00:00
|
|
|
test.afterEach(async ({ users }) => {
|
|
|
|
await users.deleteAll();
|
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();
|
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
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await pro.login();
|
2022-03-24 17:32:28 +00:00
|
|
|
await page.goto("/bookings/upcoming");
|
2022-05-11 20:36:38 +00:00
|
|
|
await page.locator('[data-testid="reschedule"]').nth(0).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-05-14 03:02:10 +00:00
|
|
|
test("Can cancel the recently created booking and rebook the same timeslot", async ({ page, users }) => {
|
2022-03-24 17:32:28 +00:00
|
|
|
await bookFirstEvent(page);
|
2021-12-13 23:10:10 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
const [pro] = users.get();
|
|
|
|
await pro.login();
|
|
|
|
|
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-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
|
|
|
});
|
2021-10-13 13:26:56 +00:00
|
|
|
});
|