|
| 1 | +import { expect, test } from '@playwright/test' |
| 2 | + |
| 3 | +test('has toolbar and syncs Delta preview on text change', async ({ page }) => { |
| 4 | + await page.goto('http://localhost:5173/tiny-editor/docs/demo/get-content') |
| 5 | + |
| 6 | + const block = page.locator('.vp-raw').filter({ has: page.locator('#editor-get-content-delta') }) |
| 7 | + const toolbar = block.locator('.ql-toolbar').first() |
| 8 | + const editor = page.locator('#editor-get-content-delta .ql-editor') |
| 9 | + const preview = block.locator('.article.ql-editor') |
| 10 | + |
| 11 | + await expect(toolbar).toBeVisible({ timeout: 30_000 }) |
| 12 | + await expect(editor).toBeVisible({ timeout: 30_000 }) |
| 13 | + await expect(preview).toBeVisible({ timeout: 30_000 }) |
| 14 | + await expect(editor).toContainText('Hello') |
| 15 | + await expect(editor).toContainText('TinyEditor') |
| 16 | + |
| 17 | + const initialDelta = JSON.parse(await preview.innerText()) |
| 18 | + expect(initialDelta.ops).toEqual( |
| 19 | + expect.arrayContaining([ |
| 20 | + expect.objectContaining({ insert: 'Hello ' }), |
| 21 | + expect.objectContaining({ insert: 'TinyEditor', attributes: { bold: true } }), |
| 22 | + expect.objectContaining({ insert: '!\n' }), |
| 23 | + ]), |
| 24 | + ) |
| 25 | + |
| 26 | + await editor.click() |
| 27 | + await page.keyboard.type(' More') |
| 28 | + await expect(preview).toContainText('More') |
| 29 | + |
| 30 | + const updatedDelta = JSON.parse(await preview.innerText()) |
| 31 | + expect(updatedDelta.ops).toEqual( |
| 32 | + expect.arrayContaining([expect.objectContaining({ insert: expect.stringContaining('More') })]), |
| 33 | + ) |
| 34 | +}) |
0 commit comments