From 31a8f25bb6a44339c23f439d11cf314e6b424218 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Thu, 7 Apr 2022 13:04:19 +0530 Subject: [PATCH] Fix E2E Tests and Fix broken success page and non existing user URL (#2411) --- apps/web/pages/[user]/[type].tsx | 2 +- apps/web/pages/success.tsx | 6 +++--- apps/web/playwright/auth/delete-account.test.ts | 1 + apps/web/playwright/booking-pages.test.ts | 4 ++-- apps/web/playwright/dynamic-booking-pages.test.ts | 2 ++ apps/web/playwright/lib/testUtils.ts | 4 ++-- test | 0 7 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 test diff --git a/apps/web/pages/[user]/[type].tsx b/apps/web/pages/[user]/[type].tsx index 238a4220fa..e8ec88bdf4 100644 --- a/apps/web/pages/[user]/[type].tsx +++ b/apps/web/pages/[user]/[type].tsx @@ -141,7 +141,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) => }, }); - if (!users) { + if (!users || !users.length) { return { notFound: true, }; diff --git a/apps/web/pages/success.tsx b/apps/web/pages/success.tsx index d3d63fe836..974a6597b3 100644 --- a/apps/web/pages/success.tsx +++ b/apps/web/pages/success.tsx @@ -487,10 +487,10 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { const profile = { name: eventType.team?.name || eventType.users[0]?.name || null, - email: eventType.team ? null : eventType.users[0].email, + email: eventType.team ? null : eventType.users[0].email || null, theme: (!eventType.team?.name && eventType.users[0]?.theme) || null, - brandColor: eventType.team ? null : eventType.users[0].brandColor, - darkBrandColor: eventType.team ? null : eventType.users[0].darkBrandColor, + brandColor: eventType.team ? null : eventType.users[0].brandColor || null, + darkBrandColor: eventType.team ? null : eventType.users[0].darkBrandColor || null, }; return { diff --git a/apps/web/playwright/auth/delete-account.test.ts b/apps/web/playwright/auth/delete-account.test.ts index 45f8d5b1a6..3ba706388d 100644 --- a/apps/web/playwright/auth/delete-account.test.ts +++ b/apps/web/playwright/auth/delete-account.test.ts @@ -1,6 +1,7 @@ import { expect, test } from "@playwright/test"; test("Can delete user account", async ({ page }) => { + //FIXME: This test depends on seed. // Login to account to delete await page.goto(`/auth/login`); // Click input[name="email"] diff --git a/apps/web/playwright/booking-pages.test.ts b/apps/web/playwright/booking-pages.test.ts index 8e2156e43a..9ffcf471b2 100644 --- a/apps/web/playwright/booking-pages.test.ts +++ b/apps/web/playwright/booking-pages.test.ts @@ -77,11 +77,11 @@ test.describe("pro user", () => { test.use({ storageState: "playwright/artifacts/proStorageState.json" }); test.beforeEach(async ({ page }) => { + await deleteAllBookingsByEmail("pro@example.com"); await page.goto("/pro"); }); - test.afterAll(async () => { - // delete test bookings + test.afterEach(async () => { await deleteAllBookingsByEmail("pro@example.com"); }); diff --git a/apps/web/playwright/dynamic-booking-pages.test.ts b/apps/web/playwright/dynamic-booking-pages.test.ts index 65510d0c8e..5eba38df9e 100644 --- a/apps/web/playwright/dynamic-booking-pages.test.ts +++ b/apps/web/playwright/dynamic-booking-pages.test.ts @@ -12,6 +12,8 @@ test.describe("dynamic booking", () => { test.use({ storageState: "playwright/artifacts/proStorageState.json" }); test.beforeEach(async ({ page }) => { + await deleteAllBookingsByEmail("pro@example.com"); + await deleteAllBookingsByEmail("free@example.com"); await page.goto("/pro+free"); }); diff --git a/apps/web/playwright/lib/testUtils.ts b/apps/web/playwright/lib/testUtils.ts index 5b63c7c761..88d258170a 100644 --- a/apps/web/playwright/lib/testUtils.ts +++ b/apps/web/playwright/lib/testUtils.ts @@ -72,7 +72,7 @@ export async function selectFirstAvailableTimeSlotNextMonth(page: Page) { // @TODO: Find a better way to make test wait for full month change render to end // so it can click up on the right day, also when resolve remove other todos // Waiting for full month increment - await page.waitForTimeout(400); + await page.waitForTimeout(1000); // TODO: Find out why the first day is always booked on tests await page.locator('[data-testid="day"][data-disabled="false"]').nth(1).click(); await page.click('[data-testid="time"]'); @@ -83,7 +83,7 @@ export async function selectSecondAvailableTimeSlotNextMonth(page: Page) { // @TODO: Find a better way to make test wait for full month change render to end // so it can click up on the right day, also when resolve remove other todos // Waiting for full month increment - await page.waitForTimeout(400); + await page.waitForTimeout(1000); // TODO: Find out why the first day is always booked on tests await page.locator('[data-testid="day"][data-disabled="false"]').nth(1).click(); await page.locator('[data-testid="time"]').nth(1).click(); diff --git a/test b/test new file mode 100644 index 0000000000..e69de29bb2