|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | + |
| 3 | +test.describe("Chat", () => { |
| 4 | + test.beforeEach(async ({ page }) => { |
| 5 | + await page.setViewportSize({ width: 1280, height: 720 }); |
| 6 | + await page.goto("/"); |
| 7 | + await page.waitForTimeout(2000); |
| 8 | + }); |
| 9 | + |
| 10 | + test("welcome message displayed on load", async ({ page }) => { |
| 11 | + await expect(page.getByText("Welcome to HydroWatch AI").first()).toBeVisible(); |
| 12 | + }); |
| 13 | + |
| 14 | + test("suggestion buttons visible", async ({ page }) => { |
| 15 | + await expect(page.getByRole("button", { name: "Show anomalies in the viewport" }).first()).toBeVisible(); |
| 16 | + await expect(page.getByRole("button", { name: "Region statistics" }).first()).toBeVisible(); |
| 17 | + }); |
| 18 | + |
| 19 | + test("suggestion button fills input", async ({ page }) => { |
| 20 | + await page.getByRole("button", { name: "Region statistics" }).first().click(); |
| 21 | + const input = page.getByPlaceholder("Ask about wells, anomalies...").first(); |
| 22 | + await expect(input).toHaveValue("Region statistics"); |
| 23 | + }); |
| 24 | + |
| 25 | + test("send message shows user bubble", async ({ page }) => { |
| 26 | + const input = page.getByPlaceholder("Ask about wells, anomalies...").first(); |
| 27 | + await input.fill("test message"); |
| 28 | + await page.getByRole("button", { name: "Send" }).first().click(); |
| 29 | + await expect(page.getByText("test message").first()).toBeVisible(); |
| 30 | + }); |
| 31 | + |
| 32 | + test("send button disabled when input empty", async ({ page }) => { |
| 33 | + const sendBtn = page.getByRole("button", { name: "Send" }).first(); |
| 34 | + await expect(sendBtn).toBeDisabled(); |
| 35 | + }); |
| 36 | + |
| 37 | + test("loading indicator appears after send", async ({ page }) => { |
| 38 | + const input = page.getByPlaceholder("Ask about wells, anomalies...").first(); |
| 39 | + await input.fill("Region statistics"); |
| 40 | + await page.getByRole("button", { name: "Send" }).first().click(); |
| 41 | + await expect(page.getByRole("button", { name: "Stop" }).first()).toBeVisible({ timeout: 5000 }); |
| 42 | + }); |
| 43 | + |
| 44 | + test("SSE response appears after sending", async ({ page }) => { |
| 45 | + test.setTimeout(60000); |
| 46 | + const input = page.getByPlaceholder("Ask about wells, anomalies...").first(); |
| 47 | + await input.fill("Region statistics"); |
| 48 | + await page.getByRole("button", { name: "Send" }).first().click(); |
| 49 | + // Wait for Send button to reappear (means response complete) |
| 50 | + await expect(page.getByRole("button", { name: "Send" }).first()).toBeVisible({ timeout: 45000 }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments