Skip to content
File

Blob: tests/e2e/specs/17-discriminated-awareness.spec.ts

typescript53 lines
1import { test, expect, createTestPage, createShareLink, expectNoChangeFor } from "../fixtures/bland-test";
2import { TEST_CREDENTIALS } from "../harness";
3 
4test.describe("discriminated awareness", () => {
5 test("share viewer never receives the member's real name over the wire", async ({
6 authenticatedPage: { page, accessToken },
7 e2eWorkspace,
8 browser,
9 }) => {
10 const testPage = await createTestPage(page, accessToken, "Discriminated Awareness Test", e2eWorkspace);
11 const share = await createShareLink(page, accessToken, testPage.pageId, "view");
12 
13 await page.goto(`/${testPage.workspaceSlug}/${testPage.pageId}`);
14 const memberEditor = page.locator(".tiptap[contenteditable='true']");
15 await memberEditor.waitFor({ timeout: 30_000 });
16 await expect(page.getByText("Connected")).toBeVisible({ timeout: 15_000 });
17 
18 const anonContext = await browser.newContext();
19 const shareViewer = await anonContext.newPage();
20 
21 const framePayloads: string[] = [];
22 shareViewer.on("websocket", (ws) => {
23 ws.on("framereceived", (event) => {
24 const payload = event.payload;
25 framePayloads.push(typeof payload === "string" ? payload : Buffer.from(payload).toString("utf8"));
26 });
27 });
28 
29 try {
30 await shareViewer.goto(`/s/${share.token}`);
31 const shareEditor = shareViewer.locator(".tiptap");
32 await shareEditor.waitFor({ timeout: 30_000 });
33 
34 await memberEditor.click();
35 await page.keyboard.type("Hello collaborators");
36 await expect(shareEditor).toContainText("Hello collaborators", { timeout: 15_000 });
37 
38 await expectNoChangeFor(() => framePayloads.join("\n").includes(TEST_CREDENTIALS.name), 1_500);
39 const combined = framePayloads.join("\n");
40 expect(combined).not.toContain(TEST_CREDENTIALS.name);
41 
42 const labels = shareViewer.locator(".collaboration-carets__label");
43 const count = await labels.count();
44 for (let i = 0; i < count; i++) {
45 const text = (await labels.nth(i).textContent()) ?? "";
46 expect(text).not.toContain(TEST_CREDENTIALS.name);
47 }
48 } finally {
49 await anonContext.close();
50 }
51 });
52});