This repository has been archived on 2026-05-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
app/apps/e2e/tests/fixtures.ts
T
Lint Roller a466053000 E2E tests: add login and impersonation test coverage (GRO-77)
- apps/e2e/tests/login.spec.ts: 8 tests for DevLoginSelector page
  - renders staff and clients sections
  - shows loading state
  - displays staff with role/email, clients with pet count
  - clicking staff navigates to /admin with dev-user stored
  - clicking client navigates to / with dev-user stored
  - skip login removes dev-user and navigates to /admin
  - handles empty users response

- apps/e2e/tests/impersonation.spec.ts: 8 tests for ImpersonationBanner
  - banner displays when session is active
  - shows reason and started time
  - End Session and Audit buttons visible
  - clicking End Session calls API and hides banner
  - Extend button appears when time < 5 mins and not extended
  - URL is cleaned when session ends

- apps/e2e/tests/fixtures.ts: added /api/dev/users mock for login tests
2026-03-21 23:47:01 +00:00

58 lines
1.9 KiB
TypeScript

import { test as base } from "@playwright/test";
/**
* Custom test fixture that bypasses the dev login redirect for E2E tests.
*
* When AUTH_DISABLED=true, the app fetches /api/dev/config and redirects to
* /login if no dev-user is in localStorage. This fixture:
* 1. Mocks /api/dev/config to return authDisabled: false
* 2. Seeds localStorage with a dev user as a fallback
*
* This ensures E2E tests render pages directly without the login redirect.
*/
const MOCK_DEV_USERS = {
staff: [
{ id: "staff-1", name: "Alice Groomer", email: "alice@groombook.dev", role: "groomer" },
{ id: "staff-2", name: "Bob Manager", email: "bob@groombook.dev", role: "manager" },
],
clients: [
{ id: "client-1", name: "Carol Client", email: "carol@example.com", petCount: 2 },
{ id: "client-2", name: "Dave Client", email: null, petCount: 1 },
],
};
export const test = base.extend({
page: async ({ page }, use) => {
// Mock the dev config endpoint so the app skips the auth-disabled redirect
await page.route("**/api/dev/config", (route) =>
route.fulfill({ json: { authDisabled: false } })
);
// Mock the dev users endpoint for login selector tests
await page.route("**/api/dev/users", (route) =>
route.fulfill({ json: MOCK_DEV_USERS })
);
// Mock the branding endpoint so BrandingProvider resolves immediately
await page.route("**/api/branding", (route) =>
route.fulfill({
json: {
businessName: "GroomBook",
primaryColor: "#4f8a6f",
accentColor: "#8b7355",
logoBase64: null,
logoMimeType: null,
},
})
);
// Seed localStorage as a fallback in case the mock is bypassed
await page.addInitScript(() => {
localStorage.setItem(
"dev-user",
JSON.stringify({ type: "staff", id: "dev-user", name: "Dev User" })
);
});
await use(page);
},
});
export { expect } from "@playwright/test";