fix(e2e): seed dev user in localStorage to prevent login redirect
E2E tests were failing because the dev login selector redirects to /login when AUTH_DISABLED=true and no dev user is in localStorage. Added a shared Playwright fixture that pre-seeds localStorage with a default dev user before each test. Also rebased onto latest main to resolve merge conflict in App.test.tsx. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
import { test, expect } from "./fixtures.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Booking portal happy-path E2E test.
|
* Booking portal happy-path E2E test.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
import { test, expect } from "./fixtures.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client management E2E tests.
|
* Client management E2E tests.
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { test as base } from "@playwright/test";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom test fixture that seeds a dev user in localStorage before each test.
|
||||||
|
*
|
||||||
|
* When AUTH_DISABLED=true, the app redirects to /login if no dev-user is set.
|
||||||
|
* This fixture ensures E2E tests bypass that redirect by pre-selecting a
|
||||||
|
* default staff user.
|
||||||
|
*/
|
||||||
|
export const test = base.extend({
|
||||||
|
page: async ({ page }, use) => {
|
||||||
|
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";
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
import { test, expect } from "./fixtures.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Navigation smoke tests — verifies that each page loads without errors.
|
* Navigation smoke tests — verifies that each page loads without errors.
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ const originalFetch = window.fetch;
|
|||||||
/**
|
/**
|
||||||
* Patches global fetch to include X-Dev-User-Id header on API requests
|
* Patches global fetch to include X-Dev-User-Id header on API requests
|
||||||
* when a dev user is selected via the login selector.
|
* when a dev user is selected via the login selector.
|
||||||
|
*
|
||||||
|
* Intentionally mutates window.fetch — this is dev-only (AUTH_DISABLED=true).
|
||||||
*/
|
*/
|
||||||
export function installDevFetchInterceptor() {
|
export function installDevFetchInterceptor() {
|
||||||
window.fetch = function (input: RequestInfo | URL, init?: RequestInit) {
|
window.fetch = function (input: RequestInfo | URL, init?: RequestInit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user