File
Blob: tests/e2e/specs/21-ai-summarize.spec.ts
| 1 | import { test, expect, createTestPage, waitForPersistedSnapshot } from "../fixtures/bland-test"; |
| 2 | |
| 3 | test.describe("AI summarize + ask page (mock backend)", () => { |
| 4 | test.slow(); |
| 5 | test("summarize button fetches a mock summary and ask streams an answer", async ({ |
| 6 | authenticatedPage: { page, accessToken }, |
| 7 | e2eWorkspace, |
| 8 | }) => { |
| 9 | const testPage = await createTestPage(page, accessToken, "AI Summarize Target", e2eWorkspace); |
| 10 | await page.goto(`/${testPage.workspaceSlug}/${testPage.pageId}`); |
| 11 | |
| 12 | const editor = page.locator(".tiptap[contenteditable='true']"); |
| 13 | await editor.waitFor({ timeout: 30_000 }); |
| 14 | await editor.click(); |
| 15 | |
| 16 | await page.keyboard.type("Launch freeze begins Thursday. Rollout is staged by region."); |
| 17 | await expect(page.getByText("Connected")).toBeVisible({ timeout: 15_000 }); |
| 18 | |
| 19 | await waitForPersistedSnapshot(page, accessToken, { |
| 20 | ...testPage, |
| 21 | expectedText: "Launch freeze begins Thursday. Rollout is staged by region.", |
| 22 | }); |
| 23 | |
| 24 | const summarizeResponsePromise = page.waitForResponse((res) => |
| 25 | res.url().includes(`/workspaces/${testPage.workspaceId}/pages/${testPage.pageId}/summarize`), |
| 26 | ); |
| 27 | |
| 28 | const summarizeButton = page.locator('button[aria-label="Summarize page"]'); |
| 29 | await summarizeButton.waitFor({ timeout: 10_000 }); |
| 30 | await summarizeButton.click(); |
| 31 | |
| 32 | const summarizeResponse = await summarizeResponsePromise; |
| 33 | const summarizeBody = await summarizeResponse.text(); |
| 34 | if (summarizeResponse.status() !== 200) { |
| 35 | throw new Error(`summarize failed: ${summarizeResponse.status()} ${summarizeBody}`); |
| 36 | } |
| 37 | |
| 38 | const summary = page.locator('[data-testid="summarize-sheet-summary"]'); |
| 39 | await expect(summary).toBeVisible({ timeout: 15_000 }); |
| 40 | await expect(summary).toContainText("[mock-summary]"); |
| 41 | |
| 42 | const input = page.locator('[data-testid="summarize-sheet-input"]'); |
| 43 | await input.fill("What day does the freeze start?"); |
| 44 | await page.locator('[data-testid="summarize-sheet-send"]').click(); |
| 45 | |
| 46 | const answer = page.locator('[data-testid="summarize-sheet-answer"]').last(); |
| 47 | await expect(answer).toContainText("[mock-chat]", { timeout: 15_000 }); |
| 48 | }); |
| 49 | }); |