| |
| |
| |
| |
| |
| |
| import { test, expect } from "./fixtures.js"; |
|
|
| test.describe("Chat persistence", () => { |
| test("conversation survives page reload", async ({ appPage, serverUrl }) => { |
| |
| await appPage.click("[aria-label='AI Assistant']"); |
| const input = appPage.getByPlaceholder("Ask anything..."); |
| await expect(input).toBeVisible({ timeout: 3_000 }); |
|
|
| |
| await input.fill("say hello"); |
| await input.press("Enter"); |
|
|
| |
| await expect(appPage.locator("text=Hello! I'm the AI assistant.")).toBeVisible({ timeout: 10_000 }); |
|
|
| |
| await appPage.waitForTimeout(2_000); |
|
|
| |
| const chatKeys = await appPage.evaluate(() => |
| Object.keys(localStorage).filter((k) => k.startsWith("chat:")) |
| ); |
| expect(chatKeys.length).toBeGreaterThan(0); |
| expect(chatKeys[0]).toMatch(/^chat:.+:article$/); |
|
|
| |
| await appPage.reload(); |
| await appPage.waitForSelector("[aria-label='Undo']", { timeout: 15_000 }); |
|
|
| |
| await appPage.click("[aria-label='AI Assistant']"); |
| await expect(appPage.locator("text=say hello")).toBeVisible({ timeout: 5_000 }); |
| await expect(appPage.locator("text=Hello! I'm the AI assistant.")).toBeVisible({ timeout: 5_000 }); |
| }); |
|
|
| test("new conversation button clears messages", async ({ appPage }) => { |
| |
| await appPage.click("[aria-label='AI Assistant']"); |
| const input = appPage.getByPlaceholder("Ask anything..."); |
| await expect(input).toBeVisible({ timeout: 3_000 }); |
| await input.fill("test message"); |
| await input.press("Enter"); |
| await expect(appPage.locator("text=Hello! I'm the AI assistant.")).toBeVisible({ timeout: 10_000 }); |
|
|
| |
| await appPage.waitForTimeout(2_000); |
|
|
| |
| await appPage.click("[aria-label='New conversation']"); |
|
|
| |
| await expect( |
| appPage.locator("text=Ask me to write, edit, expand, or improve your article.") |
| ).toBeVisible({ timeout: 3_000 }); |
|
|
| |
| const chatKeys = await appPage.evaluate(() => |
| Object.keys(localStorage).filter((k) => k.startsWith("chat:")) |
| ); |
| expect(chatKeys.length).toBe(0); |
| }); |
|
|
| test("stable user identity across reloads", async ({ appPage }) => { |
| const userName1 = await appPage.evaluate( |
| () => JSON.parse(localStorage.getItem("collab-editor:fallback-user")!).name |
| ); |
|
|
| await appPage.reload(); |
| await appPage.waitForSelector("[aria-label='Undo']", { timeout: 15_000 }); |
|
|
| const userName2 = await appPage.evaluate( |
| () => JSON.parse(localStorage.getItem("collab-editor:fallback-user")!).name |
| ); |
|
|
| expect(userName1).toBe(userName2); |
| }); |
| }); |
|
|