File
Blob: tests/e2e/specs/19-ai-rewrite.spec.ts
| 1 | import { test, expect, createTestPage } from "../fixtures/bland-test"; |
| 2 | |
| 3 | test.describe("AI rewrite (mock backend)", () => { |
| 4 | test("bubble menu proofread streams a mock suggestion and Accept commits it", async ({ |
| 5 | authenticatedPage: { page, accessToken }, |
| 6 | e2eWorkspace, |
| 7 | }) => { |
| 8 | const testPage = await createTestPage(page, accessToken, "AI Rewrite Target", e2eWorkspace); |
| 9 | await page.goto(`/${testPage.workspaceSlug}/${testPage.pageId}`); |
| 10 | |
| 11 | const editor = page.locator(".tiptap[contenteditable='true']"); |
| 12 | await editor.waitFor({ timeout: 30_000 }); |
| 13 | await editor.click(); |
| 14 | |
| 15 | const sentence = "Teh quick brown fox jumped over the lazy dog"; |
| 16 | await page.keyboard.type(sentence); |
| 17 | await expect(editor).toContainText(sentence); |
| 18 | |
| 19 | // Select the whole paragraph. |
| 20 | await page.keyboard.press("Shift+Home"); |
| 21 | |
| 22 | const aiButton = page.locator('button[aria-label="AI actions"]'); |
| 23 | await aiButton.waitFor({ timeout: 10_000 }); |
| 24 | await aiButton.click(); |
| 25 | |
| 26 | const menu = page.locator('[role="menu"]'); |
| 27 | await expect(menu.getByRole("menuitem", { name: "Proofread" })).toBeVisible(); |
| 28 | await menu.getByRole("menuitem", { name: "Proofread" }).click(); |
| 29 | |
| 30 | const preview = page.locator(".tiptap-ai-preview"); |
| 31 | await preview.waitFor({ timeout: 15_000 }); |
| 32 | await expect(preview).toContainText("[mock-chat]"); |
| 33 | |
| 34 | const acceptBtn = preview.locator('[data-ai-suggestion-action="accept"]'); |
| 35 | await expect(acceptBtn).toBeEnabled({ timeout: 15_000 }); |
| 36 | await acceptBtn.click(); |
| 37 | |
| 38 | await expect(page.locator(".tiptap-ai-preview")).toHaveCount(0); |
| 39 | await expect(editor).toContainText("[mock-chat]"); |
| 40 | }); |
| 41 | |
| 42 | test("AI button is hidden when page content is not selected", async ({ |
| 43 | authenticatedPage: { page, accessToken }, |
| 44 | e2eWorkspace, |
| 45 | }) => { |
| 46 | const testPage = await createTestPage(page, accessToken, "AI Rewrite Empty", e2eWorkspace); |
| 47 | await page.goto(`/${testPage.workspaceSlug}/${testPage.pageId}`); |
| 48 | |
| 49 | const editor = page.locator(".tiptap[contenteditable='true']"); |
| 50 | await editor.waitFor({ timeout: 30_000 }); |
| 51 | await editor.click(); |
| 52 | |
| 53 | await expect(page.locator('button[aria-label="AI actions"]')).toHaveCount(0); |
| 54 | }); |
| 55 | }); |