Skip to content
File

Blob: tests/e2e/inbox-then-admin.spec.ts

typescript42 lines
1import { expect, test } from "playwright/test";
2import { addDomain, createTemporaryInbox, makeDomainName, signInAdmin, stubTurnstile } from "./helpers";
3 
4test("anon temp inbox + admin sign-in coexist in the same browser", async ({ page }) => {
5 const domain = makeDomainName("inbox-then-admin");
6 
7 await stubTurnstile(page);
8 
9 // First: a fresh operator has to set the domain up while signed in.
10 // Sign out afterwards so the rest of the test starts from an anon
11 // session with no admin cookie.
12 await signInAdmin(page);
13 await addDomain(page, domain);
14 await page.getByRole("button", { name: /sign out/i }).click();
15 await expect(page.getByRole("link", { name: /sign in with tessera/i })).toBeVisible();
16 
17 // Anon temp inbox path: no admin cookie, bearer token in localStorage.
18 const inbox = await createTemporaryInbox(page, domain);
19 
20 // The user inbox view shows the bearer-owner extend button.
21 await expect(page.getByRole("heading", { level: 1, name: inbox })).toBeVisible();
22 await expect(page.getByRole("button", { name: /Sign in/i })).toHaveCount(0);
23 
24 // Now sign in as admin in the same browser. Admin cookie is added on
25 // top of the existing bearer in localStorage.
26 await signInAdmin(page);
27 
28 // Admin console lists temporary inboxes including the one just created.
29 await expect(page.getByText(inbox, { exact: true })).toBeVisible();
30 
31 // Visiting the bearer-owner inbox URL (no `?admin=1`) keeps owner mode:
32 // the extend button (an owner-only affordance) is still rendered.
33 await page.goto(`/inbox/${encodeURIComponent(inbox)}`);
34 await expect(page.getByRole("heading", { level: 1, name: inbox })).toBeVisible();
35 
36 // Visiting the same inbox with `?admin=1` switches to admin-inspect.
37 // The detail panel surfaces the admin-only "View raw" affordance once
38 // an email is opened, but for the smoke we just confirm the page renders.
39 await page.goto(`/inbox/${encodeURIComponent(inbox)}?admin=1`);
40 await expect(page.getByRole("heading", { level: 1, name: inbox })).toBeVisible();
41});