|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +const STORE_KEY = "openconcho:instances"; |
| 4 | +const STORE_VALUE = JSON.stringify({ |
| 5 | + instances: [{ id: "i1", name: "Local", baseUrl: "http://localhost:9999", token: "" }], |
| 6 | + activeId: "i1", |
| 7 | +}); |
| 8 | + |
| 9 | +test.describe("Dreams route", () => { |
| 10 | + test.beforeEach(async ({ context }) => { |
| 11 | + await context.addInitScript( |
| 12 | + ([key, value]) => { |
| 13 | + window.localStorage.setItem(key, value); |
| 14 | + }, |
| 15 | + [STORE_KEY, STORE_VALUE], |
| 16 | + ); |
| 17 | + // Stub the conclusions/list endpoint so the route can render real dreams. |
| 18 | + // :9999 is unreachable; this intercept replaces the network call entirely. |
| 19 | + // Use a function matcher so the trailing query string (?page=&page_size=) doesn't |
| 20 | + // break a glob. |
| 21 | + await context.route( |
| 22 | + (url) => url.pathname.endsWith("/conclusions/list"), |
| 23 | + async (route) => { |
| 24 | + const now = Date.now(); |
| 25 | + const iso = (offsetMs: number) => new Date(now - offsetMs).toISOString(); |
| 26 | + const items = [ |
| 27 | + // Dream A — burst |
| 28 | + { |
| 29 | + id: "ind-1", |
| 30 | + content: "Alice prefers asynchronous communication", |
| 31 | + observer_id: "alice", |
| 32 | + observed_id: "bob", |
| 33 | + session_id: "sess-1", |
| 34 | + created_at: iso(1000), |
| 35 | + conclusion_type: "inductive", |
| 36 | + reasoning_tree: { |
| 37 | + conclusion_id: "ind-1", |
| 38 | + premises: [{ conclusion_id: "ded-1" }], |
| 39 | + }, |
| 40 | + }, |
| 41 | + { |
| 42 | + id: "ded-1", |
| 43 | + content: "Alice mentioned email twice and declined two meetings", |
| 44 | + observer_id: "alice", |
| 45 | + observed_id: "bob", |
| 46 | + session_id: "sess-1", |
| 47 | + created_at: iso(2000), |
| 48 | + conclusion_type: "deductive", |
| 49 | + reasoning_tree: { |
| 50 | + conclusion_id: "ded-1", |
| 51 | + premises: [{ conclusion_id: "exp-1" }, { conclusion_id: "exp-2" }], |
| 52 | + }, |
| 53 | + }, |
| 54 | + { |
| 55 | + id: "exp-1", |
| 56 | + content: "Alice said 'just email me'", |
| 57 | + observer_id: "alice", |
| 58 | + observed_id: "bob", |
| 59 | + session_id: "sess-1", |
| 60 | + created_at: iso(3000), |
| 61 | + conclusion_type: "explicit", |
| 62 | + }, |
| 63 | + { |
| 64 | + id: "exp-2", |
| 65 | + content: "Alice declined the Tuesday standup", |
| 66 | + observer_id: "alice", |
| 67 | + observed_id: "bob", |
| 68 | + session_id: "sess-1", |
| 69 | + created_at: iso(4000), |
| 70 | + conclusion_type: "explicit", |
| 71 | + }, |
| 72 | + // Dream B — 30 minutes ago, different pair → clusters separately |
| 73 | + { |
| 74 | + id: "ded-2", |
| 75 | + content: "Carol responds in the evenings", |
| 76 | + observer_id: "carol", |
| 77 | + observed_id: "dan", |
| 78 | + session_id: "sess-2", |
| 79 | + created_at: iso(30 * 60_000), |
| 80 | + conclusion_type: "deductive", |
| 81 | + }, |
| 82 | + ]; |
| 83 | + await route.fulfill({ |
| 84 | + status: 200, |
| 85 | + contentType: "application/json", |
| 86 | + body: JSON.stringify({ |
| 87 | + items, |
| 88 | + total: items.length, |
| 89 | + pages: 1, |
| 90 | + page: 1, |
| 91 | + size: items.length, |
| 92 | + }), |
| 93 | + }); |
| 94 | + }, |
| 95 | + ); |
| 96 | + }); |
| 97 | + |
| 98 | + test("shows a Dreams entry in the workspace sub-nav", async ({ page }) => { |
| 99 | + await page.goto("/workspaces/ws-test/dreams"); |
| 100 | + // Sidebar link with the Dreams label |
| 101 | + const dreamsLink = page.getByRole("link", { name: /^Dreams$/ }); |
| 102 | + await expect(dreamsLink.first()).toBeVisible(); |
| 103 | + }); |
| 104 | + |
| 105 | + test("renders heading and breadcrumb on the dreams route", async ({ page }) => { |
| 106 | + await page.goto("/workspaces/ws-test/dreams"); |
| 107 | + await expect(page.getByRole("heading", { name: /^Dreams$/ })).toBeVisible(); |
| 108 | + // Breadcrumb specifically — the sidebar has a "Workspaces" link too, so scope. |
| 109 | + await expect( |
| 110 | + page.getByLabel("Breadcrumb").getByRole("link", { name: "Workspaces" }), |
| 111 | + ).toBeVisible(); |
| 112 | + }); |
| 113 | + |
| 114 | + test("clusters mocked conclusions into dreams and opens detail on click", async ({ page }) => { |
| 115 | + await page.goto("/workspaces/ws-test/dreams"); |
| 116 | + |
| 117 | + // Two dreams: alice→bob burst, and the older carol→dan |
| 118 | + const rows = page.locator('button[aria-pressed]'); |
| 119 | + await expect(rows).toHaveCount(2); |
| 120 | + |
| 121 | + // Alice→bob row should show count chips |
| 122 | + await expect(rows.first()).toContainText("alice"); |
| 123 | + await expect(rows.first()).toContainText("bob"); |
| 124 | + await expect(rows.first()).toContainText("2 explicit"); |
| 125 | + await expect(rows.first()).toContainText("1 deductive"); |
| 126 | + await expect(rows.first()).toContainText("1 inductive"); |
| 127 | + |
| 128 | + // Click → detail panel renders three columns |
| 129 | + await rows.first().click(); |
| 130 | + await expect(page.getByText("Dream detail")).toBeVisible(); |
| 131 | + await expect(page.getByText("Explicit", { exact: true })).toBeVisible(); |
| 132 | + await expect(page.getByText("Deductive", { exact: true })).toBeVisible(); |
| 133 | + await expect(page.getByText("Inductive", { exact: true })).toBeVisible(); |
| 134 | + }); |
| 135 | + |
| 136 | + test("expands premise tree for an inductive conclusion", async ({ page }) => { |
| 137 | + await page.goto("/workspaces/ws-test/dreams"); |
| 138 | + await page.locator('button[aria-pressed]').first().click(); |
| 139 | + |
| 140 | + const showPremises = page.getByRole("button", { name: /^Show premises$/i }); |
| 141 | + await expect(showPremises).toBeVisible(); |
| 142 | + await showPremises.click(); |
| 143 | + |
| 144 | + // The reasoning chain renders with the deductive premise (ded-1) |
| 145 | + await expect(page.getByText("Reasoning chain")).toBeVisible(); |
| 146 | + await expect(page.getByLabel("Premise tree")).toBeVisible(); |
| 147 | + }); |
| 148 | +}); |
0 commit comments