File
Blob: tests/e2e/specs/16-callout-block.spec.ts
| 1 | import { test, expect, createShareLink, createTestPage, waitForPersistedSnapshot } from "../fixtures/bland-test"; |
| 2 | |
| 3 | test.describe("callout block", () => { |
| 4 | test("slash inserts a callout, kind picker updates attrs, body persists through reload", async ({ |
| 5 | authenticatedPage: { page, accessToken }, |
| 6 | e2eWorkspace, |
| 7 | }) => { |
| 8 | const testPage = await createTestPage(page, accessToken, "Callout Insert", 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 | await page.keyboard.type("/callout"); |
| 16 | const slashMenu = page.locator(".tiptap-slash-menu"); |
| 17 | await slashMenu.waitFor({ timeout: 10_000 }); |
| 18 | await expect(slashMenu.getByText("Callout")).toBeVisible(); |
| 19 | await page.keyboard.press("Enter"); |
| 20 | |
| 21 | const callout = editor.locator(".tiptap-callout").first(); |
| 22 | await expect(callout).toBeVisible(); |
| 23 | await expect(callout).toHaveAttribute("data-callout-kind", "info"); |
| 24 | |
| 25 | await page.keyboard.type("Deploy freeze starts Thursday"); |
| 26 | await expect(callout).toContainText("Deploy freeze starts Thursday"); |
| 27 | |
| 28 | await callout.locator(".tiptap-callout-kind-btn").click(); |
| 29 | const kindMenu = page.locator('[role="menu"][aria-label="Callout kind"]'); |
| 30 | await kindMenu.waitFor({ timeout: 5_000 }); |
| 31 | await kindMenu.locator('[role="menuitemradio"][data-callout-kind="warning"]').click(); |
| 32 | |
| 33 | await expect(callout).toHaveAttribute("data-callout-kind", "warning"); |
| 34 | await expect(callout).toContainText("Deploy freeze starts Thursday"); |
| 35 | |
| 36 | await expect(page.getByText("Connected")).toBeVisible({ timeout: 15_000 }); |
| 37 | await waitForPersistedSnapshot(page, accessToken, { ...testPage, expectedText: "Deploy freeze starts Thursday" }); |
| 38 | |
| 39 | await page.reload(); |
| 40 | const editorAfterReload = page.locator(".tiptap"); |
| 41 | await editorAfterReload.waitFor({ timeout: 30_000 }); |
| 42 | |
| 43 | const reloaded = editorAfterReload.locator(".tiptap-callout").first(); |
| 44 | await expect(reloaded).toBeVisible(); |
| 45 | await expect(reloaded).toHaveAttribute("data-callout-kind", "warning"); |
| 46 | await expect(reloaded).toContainText("Deploy freeze starts Thursday"); |
| 47 | }); |
| 48 | |
| 49 | test("view-only share renders callout with a disabled kind picker", async ({ |
| 50 | authenticatedPage: { page, accessToken }, |
| 51 | e2eWorkspace, |
| 52 | browser, |
| 53 | }) => { |
| 54 | const testPage = await createTestPage(page, accessToken, "Callout Share", e2eWorkspace); |
| 55 | await page.goto(`/${testPage.workspaceSlug}/${testPage.pageId}`); |
| 56 | |
| 57 | const editor = page.locator(".tiptap[contenteditable='true']"); |
| 58 | await editor.waitFor({ timeout: 30_000 }); |
| 59 | await editor.click(); |
| 60 | |
| 61 | await page.keyboard.type("/callout"); |
| 62 | await page.locator(".tiptap-slash-menu").waitFor({ timeout: 10_000 }); |
| 63 | await page.keyboard.press("Enter"); |
| 64 | |
| 65 | await page.keyboard.type("Read only callout"); |
| 66 | |
| 67 | const callout = editor.locator(".tiptap-callout").first(); |
| 68 | await callout.locator(".tiptap-callout-kind-btn").click(); |
| 69 | await page |
| 70 | .locator('[role="menu"][aria-label="Callout kind"] [role="menuitemradio"][data-callout-kind="tip"]') |
| 71 | .click(); |
| 72 | |
| 73 | await expect(callout).toHaveAttribute("data-callout-kind", "tip"); |
| 74 | await expect(page.getByText("Connected")).toBeVisible({ timeout: 15_000 }); |
| 75 | await waitForPersistedSnapshot(page, accessToken, { ...testPage, expectedText: "Read only callout" }); |
| 76 | |
| 77 | const share = await createShareLink(page, accessToken, testPage.pageId, "view"); |
| 78 | |
| 79 | const anonContext = await browser.newContext(); |
| 80 | const anonPage = await anonContext.newPage(); |
| 81 | await anonPage.goto(`/s/${share.token}`); |
| 82 | |
| 83 | const sharedEditor = anonPage.locator(".tiptap"); |
| 84 | await sharedEditor.waitFor({ timeout: 30_000 }); |
| 85 | await expect(sharedEditor).toHaveAttribute("contenteditable", "false"); |
| 86 | |
| 87 | const sharedCallout = sharedEditor.locator(".tiptap-callout").first(); |
| 88 | await expect(sharedCallout).toBeVisible(); |
| 89 | await expect(sharedCallout).toHaveAttribute("data-callout-kind", "tip"); |
| 90 | await expect(sharedCallout).toContainText("Read only callout"); |
| 91 | |
| 92 | const sharedKindBtn = sharedCallout.locator(".tiptap-callout-kind-btn"); |
| 93 | await expect(sharedKindBtn).toBeDisabled(); |
| 94 | |
| 95 | await sharedKindBtn.click({ force: true }).catch(() => undefined); |
| 96 | await expect(anonPage.locator('[role="menu"][aria-label="Callout kind"]')).toHaveCount(0); |
| 97 | |
| 98 | await anonContext.close(); |
| 99 | }); |
| 100 | }); |