|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import { injectMockIPC, seedData, gotoApp, selectThread, sendMessageAndWait } from "./helpers"; |
| 3 | + |
| 4 | +test.beforeEach(async ({ page }) => { |
| 5 | + await injectMockIPC(page); |
| 6 | +}); |
| 7 | + |
| 8 | +test.describe("Chat area", () => { |
| 9 | + test('shows "New conversation" when thread is open with no messages', async ({ page }) => { |
| 10 | + await seedData(page, [ |
| 11 | + { name: "Proj", path: "/tmp/p", threads: [{ title: "Empty Thread" }] }, |
| 12 | + ]); |
| 13 | + await gotoApp(page); |
| 14 | + await selectThread(page, "Empty Thread"); |
| 15 | + |
| 16 | + const empty = page.locator(".chat-empty"); |
| 17 | + await expect(empty).toBeVisible(); |
| 18 | + await expect(empty).toContainText("New conversation"); |
| 19 | + }); |
| 20 | + |
| 21 | + test("renders messages for a thread", async ({ page }) => { |
| 22 | + await seedData(page, [ |
| 23 | + { |
| 24 | + name: "Proj", |
| 25 | + path: "/tmp/p", |
| 26 | + threads: [ |
| 27 | + { |
| 28 | + title: "Chat Thread", |
| 29 | + messages: [ |
| 30 | + { role: "user", content: "What is Rust?" }, |
| 31 | + { role: "assistant", content: "Rust is a systems programming language." }, |
| 32 | + ], |
| 33 | + }, |
| 34 | + ], |
| 35 | + }, |
| 36 | + ]); |
| 37 | + await gotoApp(page); |
| 38 | + await selectThread(page, "Chat Thread"); |
| 39 | + |
| 40 | + // Wait for messages to render |
| 41 | + await expect(page.locator(".message")).toHaveCount(2); |
| 42 | + }); |
| 43 | + |
| 44 | + test("messages have correct role classes", async ({ page }) => { |
| 45 | + await seedData(page, [ |
| 46 | + { |
| 47 | + name: "Proj", |
| 48 | + path: "/tmp/p", |
| 49 | + threads: [ |
| 50 | + { |
| 51 | + title: "Role Thread", |
| 52 | + messages: [ |
| 53 | + { role: "user", content: "Hello" }, |
| 54 | + { role: "assistant", content: "Hi there" }, |
| 55 | + { role: "system", content: "System notice" }, |
| 56 | + ], |
| 57 | + }, |
| 58 | + ], |
| 59 | + }, |
| 60 | + ]); |
| 61 | + await gotoApp(page); |
| 62 | + await selectThread(page, "Role Thread"); |
| 63 | + |
| 64 | + await expect(page.locator(".message")).toHaveCount(3); |
| 65 | + await expect(page.locator(".message-user")).toHaveCount(1); |
| 66 | + await expect(page.locator(".message-assistant")).toHaveCount(1); |
| 67 | + await expect(page.locator(".message-system")).toHaveCount(1); |
| 68 | + }); |
| 69 | + |
| 70 | + test("sending a message shows user bubble and streams assistant response", async ({ page }) => { |
| 71 | + await seedData(page, [ |
| 72 | + { name: "Proj", path: "/tmp/p", threads: [{ title: "Send Test" }] }, |
| 73 | + ]); |
| 74 | + await gotoApp(page); |
| 75 | + await selectThread(page, "Send Test"); |
| 76 | + |
| 77 | + // Send a message — the mock IPC will emit streaming events |
| 78 | + await sendMessageAndWait(page, "Hello Claude!"); |
| 79 | + |
| 80 | + // User message should appear |
| 81 | + const userMsg = page.locator(".message-user"); |
| 82 | + await expect(userMsg).toHaveCount(1); |
| 83 | + await expect(userMsg).toContainText("Hello Claude!"); |
| 84 | + |
| 85 | + // Assistant response should appear (streamed via mock agent events) |
| 86 | + const assistantMsg = page.locator(".message-assistant"); |
| 87 | + await expect(assistantMsg).toHaveCount(1); |
| 88 | + // The mock responds with: 'This is a mock response to: "Hello Claude!"' |
| 89 | + await expect(assistantMsg).toContainText("mock response"); |
| 90 | + |
| 91 | + // Streaming should be done — no cursor visible |
| 92 | + await expect(page.locator(".cursor")).toHaveCount(0); |
| 93 | + }); |
| 94 | +}); |
0 commit comments