| import { test, expect } from "@playwright/test"; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| test("SSE chat path renders streamed assistant response", async ({ page }) => { |
| const taskId = "task-e2e-test"; |
|
|
| |
| await page.route("**/api/projects", async (route) => { |
| await route.fulfill({ |
| status: 200, |
| contentType: "application/json", |
| body: JSON.stringify({ id: "proj-test", name: "Quick Tasks" }), |
| }); |
| }); |
|
|
| |
| await page.route("**/api/projects/proj-test/tasks", async (route) => { |
| if (route.request().method() === "POST") { |
| await route.fulfill({ |
| status: 200, |
| contentType: "application/json", |
| body: JSON.stringify({ id: taskId, projectId: "proj-test", title: "(new conversation)", createdAt: Date.now(), updatedAt: Date.now(), messages: [], artifacts: [] }), |
| }); |
| } else { |
| await route.fallback(); |
| } |
| }); |
|
|
| |
| await page.route(`**/api/tasks/${taskId}/messages/stream`, async (route) => { |
| const sseBody = [ |
| 'data: {"type":"text_delta","text":"Hello "}', |
| 'data: {"type":"text_delta","text":"world"}', |
| 'data: {"type":"done"}', |
| "", |
| ].join("\n"); |
|
|
| await route.fulfill({ |
| status: 200, |
| contentType: "text/event-stream", |
| body: sseBody, |
| }); |
| }); |
|
|
| |
| await page.route("**/api/datasets/sync/status", async (route) => { |
| await route.fulfill({ |
| status: 200, |
| contentType: "application/json", |
| body: JSON.stringify([]), |
| }); |
| }); |
|
|
| |
| await page.route(`**/api/tasks/${taskId}`, async (route) => { |
| if (route.request().method() === "PATCH") { |
| await route.fulfill({ status: 200, contentType: "application/json", body: "{}" }); |
| } else { |
| await route.fallback(); |
| } |
| }); |
|
|
| |
| await page.route(`**/api/tasks/${taskId}/messages`, async (route) => { |
| await route.fulfill({ status: 200, contentType: "application/json", body: "{}" }); |
| }); |
|
|
| await page.goto("/chat"); |
|
|
| |
| const textarea = page.locator("textarea"); |
| await expect(textarea).toBeVisible({ timeout: 10_000 }); |
|
|
| |
| await textarea.fill("Test message"); |
| await textarea.press("Enter"); |
|
|
| |
| await expect(page.locator("text=Hello world")).toBeVisible({ timeout: 10_000 }); |
|
|
| |
| await expect(page.locator("text=Connection error")).not.toBeVisible(); |
| }); |
|
|