Skip to content

Commit 0a60864

Browse files
authored
fix: Few flaky e2e test (calcom#21818)
* fix: delete dilog button not visible * fix: flaky e2e tests * Update booking.e2e.ts * update * Update booking.e2e.ts * update * Update booking.e2e.ts * Update booking.e2e.ts
1 parent cb24e5d commit 0a60864

3 files changed

Lines changed: 36 additions & 22 deletions

File tree

apps/web/playwright/fixtures/users.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,13 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
768768
* @deprecated use apiLogin instead
769769
*/
770770
login: async () => login({ ...(await self()), password: user.username }, store.page),
771+
loginOnNewBrowser: async (browser: Browser) => {
772+
const newContext = await browser.newContext();
773+
const newPage = await newContext.newPage();
774+
await login({ ...(await self()), password: user.username }, newPage);
775+
// Don't forget to: newContext.close();
776+
return [newContext, newPage] as const;
777+
},
771778
logout: async () => {
772779
await page.goto("/auth/logout");
773780
},
@@ -1074,9 +1081,11 @@ export async function apiLogin(
10741081
json: "true",
10751082
csrfToken,
10761083
};
1077-
return page.context().request.post("/api/auth/callback/credentials", {
1084+
const response = await page.context().request.post("/api/auth/callback/credentials", {
10781085
data,
10791086
});
1087+
expect(response.status()).toBe(200);
1088+
return response;
10801089
}
10811090

10821091
export async function setupEventWithPrice(eventType: Pick<Prisma.EventType, "id">, slug: string, page: Page) {

apps/web/playwright/login.2fa.e2e.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test.describe("2FA Tests", async () => {
1818
test.afterEach(async ({ users }) => {
1919
await users.deleteAll();
2020
});
21-
test("should allow a user to enable 2FA and login using 2FA", async ({ page, users }) => {
21+
test("should allow a user to enable 2FA and login using 2FA", async ({ page, users, browser }) => {
2222
// log in trail user
2323
const user = await test.step("Enable 2FA", async () => {
2424
const user = await users.create();
@@ -60,7 +60,7 @@ test.describe("2FA Tests", async () => {
6060
});
6161

6262
await test.step("Login with 2FA enabled", async () => {
63-
await user.login();
63+
const [secondContext, secondPage] = await user.loginOnNewBrowser(browser);
6464
const userWith2FaSecret = await prisma.user.findFirst({
6565
where: {
6666
id: user.id,
@@ -74,13 +74,14 @@ test.describe("2FA Tests", async () => {
7474
process.env.CALENDSO_ENCRYPTION_KEY!
7575
);
7676
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
77-
await fillOtp({ page, secret: secret! });
77+
await fillOtp({ page: secondPage, secret: secret! });
7878
await Promise.all([
79-
page.press('input[name="2fa6"]', "Enter"),
80-
page.waitForResponse("**/api/auth/callback/credentials**"),
79+
secondPage.press('input[name="2fa6"]', "Enter"),
80+
secondPage.waitForResponse("**/api/auth/callback/credentials**"),
8181
]);
82-
const shellLocator = page.locator(`[data-testid=dashboard-shell]`);
82+
const shellLocator = secondPage.locator(`[data-testid=dashboard-shell]`);
8383
await expect(shellLocator).toBeVisible();
84+
await secondContext.close();
8485
});
8586
});
8687

apps/web/playwright/organization/booking.e2e.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,11 @@ test.describe("Bookings", () => {
368368
);
369369
});
370370

371-
test("Round robin event type with confirmation required handles cancellation and rebooking correctly with the same details and slot", async ({
371+
test("Round robin event type with confirmation required handles rejection and rebooking correctly with the same details and slot", async ({
372372
page,
373373
users,
374374
orgs,
375+
browser,
375376
}) => {
376377
const org = await orgs.create({
377378
name: "TestOrg",
@@ -421,38 +422,41 @@ test.describe("Bookings", () => {
421422
const bookingUid = page.url().split("/booking/")[1];
422423
expect(bookingUid).not.toBeNull();
423424

424-
// Login as the host to cancel the booking
425425
await page.goto("/auth/logout");
426-
const allUsers = await users.get();
426+
427+
const allUsers = users.get();
427428
const hostUser = allUsers.find((mate) => mate.name === firstHost);
428429
if (!hostUser) throw new Error("Host not found");
429430

430431
await hostUser.apiLogin();
432+
const [secondContext, secondPage] = await hostUser.apiLoginOnNewBrowser(browser);
431433

432-
// Cancel the booking
433-
await page.goto(`/booking/${bookingUid}`);
434-
await page.getByTestId("cancel").click();
435-
await page.getByTestId("confirm_cancel").click();
436-
await page.waitForResponse((response) => response.url().includes("/api/cancel"));
434+
// Reject the booking
435+
await secondPage.goto("/bookings/upcoming");
436+
await secondPage.click('[data-testid="reject"]');
437+
await submitAndWaitForResponse(secondPage, "/api/trpc/bookings/confirm?batch=1", {
438+
action: () => secondPage.click('[data-testid="rejection-confirm"]'),
439+
});
437440

438441
// Logout and go back to booking page
439-
await page.goto("/auth/logout");
440-
await page.goto(`/org/${org.slug}/${team.slug}/${teamEvent.slug}`);
442+
await secondPage.goto("/auth/logout");
443+
await secondPage.goto(`/org/${org.slug}/${team.slug}/${teamEvent.slug}`);
441444

442445
// Rebook with the same details
443-
await selectFirstAvailableTimeSlotNextMonth(page);
444-
await bookTimeSlot(page);
445-
await expect(page.getByTestId("success-page")).toBeVisible();
446+
await selectFirstAvailableTimeSlotNextMonth(secondPage);
447+
await bookTimeSlot(secondPage);
448+
await expect(secondPage.getByTestId("success-page")).toBeVisible();
446449

447450
// Verify a new host is assigned
448-
const newHost = await page.getByTestId("booking-host-name").textContent();
451+
const newHost = await secondPage.getByTestId("booking-host-name").textContent();
449452
expect(newHost).not.toBeNull();
450453
expect(newHost).toBe(firstHost);
451454

452455
// Verify the booking was successful by checking the new booking UID
453-
const newBookingUid = page.url().split("/booking/")[1];
456+
const newBookingUid = secondPage.url().split("/booking/")[1];
454457
expect(newBookingUid).not.toBeNull();
455458
expect(newBookingUid).not.toBe(bookingUid);
459+
await secondContext.close();
456460
}
457461
);
458462
});

0 commit comments

Comments
 (0)