Files
romm/frontend/e2e/profile-role.spec.ts
Georges-Antoine Assi 9e5582230d Sign in once per role instead of per test
Every spec drove the login form, which is 15 UI logins to test something
login.spec.ts can cover on its own.

auth.setup.ts now runs first as its own project, logs each fixture user in
once and saves the session (cookies plus localStorage) to playwright/.auth/.
Specs pick an identity with `test.use({ storageState })` and start signed in.
That is preferred over building a context by hand, which would silently drop
the project's options -- baseURL, the blocked service worker, viewport.

login.spec.ts is the one place the form is exercised, on a deliberately
unauthenticated page, and it gained cover the suite never had: a rejected
password and the redirect for an anonymous visitor.

Suite: 33s -> ~19s, with 18 tests instead of 15. Verified three times against
the build and once against the dev server.
2026-07-26 14:08:37 -04:00

44 lines
1.7 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { gotoOwnProfile, seedUiState, STORAGE_STATE } from "./fixtures/auth";
// Regression cover for #3954: the profile page shipped an editable role picker,
// but `update_user` ignores `role` on a self-edit. Saving reported success and
// then silently reverted on reload -- for admins as much as for regular users.
// The role is display-only now: the chip in the identity row.
//
// Sessions come from auth.setup.ts; see login.spec.ts for the form itself.
for (const role of ["viewer", "admin"] as const) {
test.describe(`Profile page role field (${role})`, () => {
test.use({ storageState: STORAGE_STATE[role] });
test("gets no editable role control", async ({ page }) => {
await seedUiState(page, "dark");
await gotoOwnProfile(page);
// The editable rows that SHOULD be there, so a blank page can't pass.
await expect(page.locator('input[type="email"]')).toBeVisible();
// No role row in the Account Details form.
const form = page.locator(".r-v2-section-stack");
await expect(form.getByText("Role", { exact: true })).toHaveCount(0);
// And no select rendered anywhere on the page.
await expect(page.locator(".r-select")).toHaveCount(0);
});
});
}
test.describe("Profile page role chip", () => {
test.use({ storageState: STORAGE_STATE.viewer });
test("still shows the role read-only", async ({ page }) => {
await seedUiState(page, "dark");
await gotoOwnProfile(page);
// Identity row keeps the role visible -- removing the picker must not
// remove the information.
const chip = page.locator(".r-v2-profile__role-tag");
await expect(chip).toBeVisible();
await expect(chip).toHaveText(/user/i);
});
});