From 344b9e9b2bd21c853400035f73de840102159ccb Mon Sep 17 00:00:00 2001 From: Shivam Kalra Date: Fri, 28 Jul 2023 18:21:15 +0530 Subject: [PATCH] chore: team booking test (#10440) * feat: add team name in the createTeam fixture * chore: remove unnecessary variables * test: e2e booking for Round Robin EventType * feat: teammates in user fixtures * chore: DRY * fix: remove redundant todo * fix: add teamEvent title and slug in scenario * test: booking title, RR hostname --- apps/web/pages/booking/[uid].tsx | 2 +- apps/web/playwright/fixtures/users.ts | 7 +++++ apps/web/playwright/teams.e2e.ts | 40 +++++++++++++++------------ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/apps/web/pages/booking/[uid].tsx b/apps/web/pages/booking/[uid].tsx index dc0d14977b..8983f9a8e4 100644 --- a/apps/web/pages/booking/[uid].tsx +++ b/apps/web/pages/booking/[uid].tsx @@ -446,7 +446,7 @@ export default function Success(props: SuccessProps) { {bookingInfo?.user && (
- + {bookingInfo.user.name} {t("Host")} diff --git a/apps/web/playwright/fixtures/users.ts b/apps/web/playwright/fixtures/users.ts index 2af6ac85a1..69797755b7 100644 --- a/apps/web/playwright/fixtures/users.ts +++ b/apps/web/playwright/fixtures/users.ts @@ -328,6 +328,13 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => { include: { team: true }, }); }, + getFirstTeamEvent: async (teamId: number) => { + return prisma.eventType.findFirstOrThrow({ + where: { + teamId, + }, + }); + }, getPaymentCredential: async () => getPaymentCredential(store.page), setupEventWithPrice: async (eventType: Pick) => setupEventWithPrice(eventType, store.page), diff --git a/apps/web/playwright/teams.e2e.ts b/apps/web/playwright/teams.e2e.ts index 8b6e72e254..d0edf32b44 100644 --- a/apps/web/playwright/teams.e2e.ts +++ b/apps/web/playwright/teams.e2e.ts @@ -4,14 +4,7 @@ import { prisma } from "@calcom/prisma"; import { SchedulingType } from "@calcom/prisma/enums"; import { test } from "./lib/fixtures"; -import { - bookTimeSlot, - selectFirstAvailableTimeSlotNextMonth, - teamEventSlug, - teamEventTitle, - testName, - todo, -} from "./lib/testUtils"; +import { bookTimeSlot, selectFirstAvailableTimeSlotNextMonth, testName, todo } from "./lib/testUtils"; test.describe.configure({ mode: "parallel" }); @@ -74,10 +67,10 @@ test.describe("Teams", () => { test("Can create a booking for Collective EventType", async ({ page, users }) => { const ownerObj = { username: "pro-user", name: "pro-user" }; const teamMatesObj = [ - { username: "teammate-1", name: "teammate-1" }, - { username: "teammate-2", name: "teammate-2" }, - { username: "teammate-3", name: "teammate-3" }, - { username: "teammate-4", name: "teammate-4" }, + { name: "teammate-1" }, + { name: "teammate-2" }, + { name: "teammate-3" }, + { name: "teammate-4" }, ]; const owner = await users.create(ownerObj, { @@ -86,13 +79,20 @@ test.describe("Teams", () => { schedulingType: SchedulingType.COLLECTIVE, }); const { team } = await owner.getTeam(); + const { title: teamEventTitle, slug: teamEventSlug } = await owner.getFirstTeamEvent(team.id); await page.goto(`/team/${team.slug}/${teamEventSlug}`); await selectFirstAvailableTimeSlotNextMonth(page); await bookTimeSlot(page); await expect(page.locator("[data-testid=success-page]")).toBeVisible(); + + // The title of the booking + const BookingTitle = `${teamEventTitle} between ${team.name} and ${testName}`; + await expect(page.locator("[data-testid=booking-title]")).toHaveText(BookingTitle); + // The booker should be in the attendee list await expect(page.locator(`[data-testid="attendee-name-${testName}"]`)).toHaveText(testName); + // All the teammates should be in the booking for (const teammate of teamMatesObj) { await expect(page.getByText(teammate.name, { exact: true })).toBeVisible(); } @@ -102,10 +102,10 @@ test.describe("Teams", () => { test("Can create a booking for Round Robin EventType", async ({ page, users }) => { const ownerObj = { username: "pro-user", name: "pro-user" }; const teamMatesObj = [ - { username: "teammate-1", name: "teammate-1" }, - { username: "teammate-2", name: "teammate-2" }, - { username: "teammate-3", name: "teammate-3" }, - { username: "teammate-4", name: "teammate-4" }, + { name: "teammate-1" }, + { name: "teammate-2" }, + { name: "teammate-3" }, + { name: "teammate-4" }, ]; const owner = await users.create(ownerObj, { hasTeam: true, @@ -114,6 +114,7 @@ test.describe("Teams", () => { }); const { team } = await owner.getTeam(); + const { title: teamEventTitle, slug: teamEventSlug } = await owner.getFirstTeamEvent(team.id); await page.goto(`/team/${team.slug}/${teamEventSlug}`); await selectFirstAvailableTimeSlotNextMonth(page); @@ -127,9 +128,14 @@ test.describe("Teams", () => { const BookingTitle = `${teamEventTitle} between ${team.name} and ${testName}`; await expect(page.locator("[data-testid=booking-title]")).toHaveText(BookingTitle); - // TODO: Assert one of the teamates from the list to be the host + // Since all the users have the same leastRecentlyBooked value + // Anyone of the teammates could be the Host of the booking. + const chosenUser = await page.getByTestId("booking-host-name").textContent(); + expect(chosenUser).not.toBeNull(); + expect(teamMatesObj.some(({ name }) => name === chosenUser)).toBe(true); // TODO: Assert whether the user received an email }); + todo("Create a Round Robin with different leastRecentlyBooked hosts"); todo("Reschedule a Collective EventType booking"); todo("Reschedule a Round Robin EventType booking"); });