Files
calendar/apps/web/playwright/change-theme.e2e.ts
T
Volnei MunhozGitHubVolnei MunhozDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
b83f8dd6b8 fix: improve E2E test stability and reduce flakiness (#25897)
* fix: improve E2E test stability and reduce flakiness

- Replace hardcoded waits with proper Playwright waitFor assertions in slot selection
- Add explicit waits for calendar and time slot elements to be visible before clicking
- Replace fixed 2s wait in gotoRoutingLink with networkidle wait
- Replace fixed 5s email wait with retry logic (10 retries, 500ms intervals)
- Use unique usernames with timestamps to avoid parallel test collisions
- Use features fixture instead of direct prisma calls for feature flag mutations
- Fix login.e2e.ts to use unique username instead of hardcoded 'pro'
- Fix signup.e2e.ts to use unique usernames and proper feature flag handling
- Remove unused 'users' parameter from tests that don't need it

Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>

* perf: replace waitForTimeout with smart waits for faster E2E tests

- Replace 30 waitForTimeout calls with proper Playwright waits
- Use waitFor({ state: 'visible' }) for element visibility
- Use waitForLoadState('networkidle') for page load completion
- Use waitForFunction for localStorage state changes

Performance improvements:
- limit-tab.e2e.ts: 10s fixed wait -> element visibility wait
- booking-duplicate-api-calls.e2e.ts: 5s fixed wait -> networkidle
- change-theme.e2e.ts: 3s fixed wait -> localStorage state check
- team-invitation.e2e.ts: multiple 500ms-3s waits -> element waits
- booking-seats.e2e.ts: 2s waits -> dropdown visibility waits
- embed-code-generator.e2e.ts: 1s waits -> iframe visibility waits
- organization-privacy.e2e.ts: 500ms waits -> element/networkidle waits
- organization-invitation.e2e.ts: 500ms-1s waits -> element waits
- analyticsApps.e2e.ts: 1s wait -> networkidle
- integrations.e2e.ts: 1s wait -> calendar element wait
- fixtures/apps.ts: 1s waits -> element visibility waits

Co-Authored-By: Volnei Munhoz <volnei.munhoz@gmail.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2025-12-15 20:19:47 -03:00

138 lines
5.7 KiB
TypeScript

import { expect } from "@playwright/test";
import { test } from "./lib/fixtures";
test.describe("Change App Theme Test", () => {
test("change app theme to dark", async ({ page, users }) => {
const pro = await users.create();
await pro.apiLogin();
await page.goto("/settings/my-account/appearance");
await expect(page.getByTestId("dashboard-shell").getByText("Dashboard theme")).toBeVisible();
await page.click('[data-testid="appTheme-dark"]');
await page.click('[data-testid="update-app-theme-btn"]');
const toast = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast).toBeTruthy();
const darkModeClass = await page.getAttribute("html", "class");
expect(darkModeClass).toContain("dark");
const themeValue = await page.evaluate(() => localStorage.getItem("app-theme"));
expect(themeValue).toBe("dark");
});
test("change app theme to light", async ({ page, users }) => {
const pro = await users.create();
await pro.apiLogin();
await page.goto("/settings/my-account/appearance");
await expect(page.getByTestId("dashboard-shell").getByText("Dashboard theme")).toBeVisible();
await page.click('[data-testid="appTheme-light"]');
await page.click('[data-testid="update-app-theme-btn"]');
const toast = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast).toBeTruthy();
const darkModeClass = await page.getAttribute("html", "class");
expect(darkModeClass).toContain("light");
const themeValue = await page.evaluate(() => localStorage.getItem("app-theme"));
expect(themeValue).toBe("light");
});
test("change app theme to system", async ({ page, users }) => {
const pro = await users.create();
await pro.apiLogin();
await page.goto("/settings/my-account/appearance");
await expect(page.getByTestId("dashboard-shell").getByText("Dashboard theme")).toBeVisible();
await page.click('[data-testid="appTheme-light"]');
await page.click('[data-testid="update-app-theme-btn"]');
const toast1 = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast1).toBeTruthy();
await page.click('[data-testid="appTheme-system"]');
await page.click('[data-testid="update-app-theme-btn"]');
const toast2 = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast2).toBeTruthy();
// Wait for localStorage to be updated after theme change instead of fixed 3s wait
await page.waitForFunction(() => localStorage.getItem("app-theme") !== null, { timeout: 5000 });
const themeValue = await page.evaluate(() => localStorage.getItem("app-theme"));
expect(themeValue).toBe("light");
const systemTheme = await page.evaluate(() => {
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
});
expect(await page.getAttribute("html", "class")).toContain(systemTheme);
});
});
test.describe("Change Booking Page Theme Test", () => {
test("change booking page theme to dark", async ({ page, users }) => {
const pro = await users.create();
await pro.apiLogin();
await page.goto("/settings/my-account/appearance");
await expect(page.getByTestId("dashboard-shell").getByText("Dashboard theme")).toBeVisible();
//Click the "Dark" theme label
await page.click('[data-testid="theme-dark"]');
//Click the update button
await page.click('[data-testid="update-theme-btn"]');
//Wait for the toast to appear
const toast = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast).toBeTruthy();
//Go to the profile page and check if the theme is dark
await page.goto(`/${pro.username}`);
await page.reload();
await page.waitForLoadState("domcontentloaded"); // Fix the race condition
const htmlClass = await page.getAttribute("html", "class");
expect(htmlClass).toContain("dark");
});
test("change booking page theme to light", async ({ page, users }) => {
const pro = await users.create();
await pro.apiLogin();
await page.goto("/settings/my-account/appearance");
await expect(page.getByTestId("dashboard-shell").getByText("Dashboard theme")).toBeVisible();
//Click the "Light" theme label
await page.click('[data-testid="theme-light"]');
//Click the update theme button
await page.click('[data-testid="update-theme-btn"]');
//Wait for the toast to appear
const toast = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast).toBeTruthy();
//Go to the profile page and check if the theme is light
await page.goto(`/${pro.username}`);
const htmlClass = await page.getAttribute("html", "class");
expect(htmlClass).toContain("light");
});
test("change booking page theme to system", async ({ page, users }) => {
const pro = await users.create();
await pro.apiLogin();
await page.goto("/settings/my-account/appearance");
await expect(page.getByTestId("dashboard-shell").getByText("Dashboard theme")).toBeVisible();
await page.click('[data-testid="theme-light"]');
await page.click('[data-testid="update-theme-btn"]');
const toast1 = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast1).toBeTruthy();
await page.click('[data-testid="theme-system"]');
await page.click('[data-testid="update-theme-btn"]');
const toast2 = await page.waitForSelector('[data-testid="toast-success"]');
expect(toast2).toBeTruthy();
await page.goto(`/${pro.username}`);
const systemTheme = await page.evaluate(() => {
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
});
expect(await page.getAttribute("html", "class")).toContain(systemTheme);
});
});