|
| 1 | +import { expect, publish, test } from "./fixtures.ts"; |
| 2 | + |
| 3 | +test("clicking a session updates the URL to /session/:id", async ({ page, server }) => { |
| 4 | + const s1 = await publish(server.url, { html: "<p>one</p>", title: "First", agent: "a1" }); |
| 5 | + const s2 = await publish(server.url, { html: "<p>two</p>", title: "Second", agent: "a2" }); |
| 6 | + await page.goto(server.url); |
| 7 | + await expect(page.locator("#sessionList .sess")).toHaveCount(2); |
| 8 | + |
| 9 | + // click the second session row |
| 10 | + await page.locator(`#sessionList .sess[data-id="${s2.sessionId}"]`).click(); |
| 11 | + await expect(page).toHaveURL(new RegExp(`/session/${s2.sessionId}$`)); |
| 12 | + |
| 13 | + // click the first session row |
| 14 | + await page.locator(`#sessionList .sess[data-id="${s1.sessionId}"]`).click(); |
| 15 | + await expect(page).toHaveURL(new RegExp(`/session/${s1.sessionId}$`)); |
| 16 | +}); |
| 17 | + |
| 18 | +test("navigating to /session/:id selects that session", async ({ page, server }) => { |
| 19 | + await publish(server.url, { html: "<p>one</p>", title: "First", agent: "a1" }); |
| 20 | + const s2 = await publish(server.url, { html: "<p>two</p>", title: "Second", agent: "a2" }); |
| 21 | + |
| 22 | + // go directly to the second session |
| 23 | + await page.goto(`${server.url}/session/${s2.sessionId}`); |
| 24 | + await expect(page.locator(`#sessionList .sess[data-id="${s2.sessionId}"]`)).toHaveClass(/sel/); |
| 25 | + await expect(page.locator(".card .card-title")).toHaveText("Second"); |
| 26 | +}); |
| 27 | + |
| 28 | +test("navigating to /session/:id/s/:surfaceId selects the session", async ({ page, server }) => { |
| 29 | + const s1 = await publish(server.url, { html: "<p>first</p>", title: "A", agent: "pi" }); |
| 30 | + const s2 = await publish(server.url, { |
| 31 | + html: "<p>second</p>", |
| 32 | + title: "B", |
| 33 | + agent: "pi", |
| 34 | + session: s1.sessionId, |
| 35 | + }); |
| 36 | + |
| 37 | + // deep link with a surface id selects the session |
| 38 | + await page.goto(`${server.url}/session/${s1.sessionId}/s/${s2.id}`); |
| 39 | + await expect(page.locator(`#sessionList .sess[data-id="${s1.sessionId}"]`)).toHaveClass(/sel/); |
| 40 | + // both surfaces should be loaded (full session view) |
| 41 | + await expect(page.locator(".card:not(#whatsNew) .card-title")).toHaveCount(2); |
| 42 | +}); |
| 43 | + |
| 44 | +test("browser back/forward navigates between sessions", async ({ page, server }) => { |
| 45 | + const s1 = await publish(server.url, { html: "<p>one</p>", title: "First", agent: "a1" }); |
| 46 | + const s2 = await publish(server.url, { html: "<p>two</p>", title: "Second", agent: "a2" }); |
| 47 | + await page.goto(server.url); |
| 48 | + await expect(page.locator("#sessionList .sess")).toHaveCount(2); |
| 49 | + |
| 50 | + await page.locator(`#sessionList .sess[data-id="${s1.sessionId}"]`).click(); |
| 51 | + await expect(page).toHaveURL(new RegExp(`/session/${s1.sessionId}(\\b|/)`)); |
| 52 | + |
| 53 | + await page.locator(`#sessionList .sess[data-id="${s2.sessionId}"]`).click(); |
| 54 | + await expect(page).toHaveURL(new RegExp(`/session/${s2.sessionId}(\\b|/)`)); |
| 55 | + |
| 56 | + // go back — should return to first session |
| 57 | + await page.goBack(); |
| 58 | + await expect(page).toHaveURL(new RegExp(`/session/${s1.sessionId}(\\b|/)`)); |
| 59 | + await expect(page.locator(`#sessionList .sess[data-id="${s1.sessionId}"]`)).toHaveClass(/sel/); |
| 60 | + |
| 61 | + // go forward — should return to second session |
| 62 | + await page.goForward(); |
| 63 | + await expect(page).toHaveURL(new RegExp(`/session/${s2.sessionId}(\\b|/)`)); |
| 64 | + await expect(page.locator(`#sessionList .sess[data-id="${s2.sessionId}"]`)).toHaveClass(/sel/); |
| 65 | +}); |
| 66 | + |
| 67 | +test("/ redirects to the last viewed session from localStorage", async ({ page, server }) => { |
| 68 | + const s = await publish(server.url, { html: "<p>hi</p>", title: "Sticky", agent: "pi" }); |
| 69 | + |
| 70 | + // visit the session to populate localStorage |
| 71 | + await page.goto(`${server.url}/session/${s.sessionId}`); |
| 72 | + await expect(page.locator(`#sessionList .sess[data-id="${s.sessionId}"]`)).toHaveClass(/sel/); |
| 73 | + |
| 74 | + // now visit root — should redirect to the last session |
| 75 | + await page.goto(server.url); |
| 76 | + await expect(page).toHaveURL(new RegExp(`/session/${s.sessionId}$`)); |
| 77 | + await expect(page.locator(`#sessionList .sess[data-id="${s.sessionId}"]`)).toHaveClass(/sel/); |
| 78 | +}); |
| 79 | + |
| 80 | +test("scrolling through surfaces updates the URL", async ({ page, server }) => { |
| 81 | + // publish enough surfaces to force scrolling |
| 82 | + const s1 = await publish(server.url, { |
| 83 | + html: '<div style="height:800px"><h2>Top</h2></div>', |
| 84 | + title: "Surface A", |
| 85 | + agent: "pi", |
| 86 | + }); |
| 87 | + await publish(server.url, { |
| 88 | + html: '<div style="height:800px"><h2>Middle</h2></div>', |
| 89 | + title: "Surface B", |
| 90 | + agent: "pi", |
| 91 | + session: s1.sessionId, |
| 92 | + }); |
| 93 | + const s3 = await publish(server.url, { |
| 94 | + html: '<div style="height:800px"><h2>Bottom</h2></div>', |
| 95 | + title: "Surface C", |
| 96 | + agent: "pi", |
| 97 | + session: s1.sessionId, |
| 98 | + }); |
| 99 | + |
| 100 | + await page.goto(`${server.url}/session/${s1.sessionId}`); |
| 101 | + await expect(page.locator(".card:not(#whatsNew)")).toHaveCount(3); |
| 102 | + |
| 103 | + // scroll the last surface into view |
| 104 | + await page.locator(`.card[data-id="${s3.id}"]`).scrollIntoViewIfNeeded(); |
| 105 | + await expect(page).toHaveURL(new RegExp(`/session/${s1.sessionId}/s/${s3.id}$`)); |
| 106 | + |
| 107 | + // scroll back to the first surface |
| 108 | + await page.locator(`.card[data-id="${s1.id}"]`).scrollIntoViewIfNeeded(); |
| 109 | + await expect(page).toHaveURL(new RegExp(`/session/${s1.sessionId}/s/${s1.id}$`)); |
| 110 | +}); |
| 111 | + |
| 112 | +test("/s/:id standalone surface route still works unchanged", async ({ page, server }) => { |
| 113 | + const s = await publish(server.url, { html: "<h2>Standalone</h2>", title: "Solo" }); |
| 114 | + await page.goto(`${server.url}/s/${s.id}`); |
| 115 | + // standalone route renders the raw surface, not the viewer SPA |
| 116 | + await expect(page.locator("h2")).toHaveText("Standalone"); |
| 117 | + // the sidebar should NOT be present |
| 118 | + await expect(page.locator("#sessionList")).toHaveCount(0); |
| 119 | +}); |
0 commit comments