|
1 | 1 | import { test, expect } from '../../fixtures/superdoc.js'; |
2 | 2 | import { getDocumentText } from '../../helpers/document-api.js'; |
| 3 | +import { rightClickAtDocPos } from '../../helpers/editor-interactions.js'; |
| 4 | +import { getMarkedText, getSelectedText, insertTrackedChange } from '../../helpers/tracked-changes.js'; |
3 | 5 |
|
4 | 6 | test.use({ config: { toolbar: 'full', comments: 'panel', trackChanges: true, showSelection: true } }); |
5 | 7 |
|
6 | 8 | const TRACK_TEXT = 'ABCDE'; |
7 | 9 | const PARTIAL_TEXT = 'BC'; |
8 | 10 | const ACCEPT_TRACKED_CHANGES_BUTTON = 'Accept tracked changes'; |
9 | 11 |
|
10 | | -async function insertTrackedChange( |
11 | | - page: import('@playwright/test').Page, |
12 | | - options: { |
13 | | - from: number; |
14 | | - to: number; |
15 | | - text: string; |
16 | | - }, |
17 | | -) { |
18 | | - await page.evaluate((payload) => { |
19 | | - (window as any).editor.commands.insertTrackedChange({ |
20 | | - ...payload, |
21 | | - user: { name: 'Track Tester', email: 'track@example.com' }, |
22 | | - }); |
23 | | - }, options); |
24 | | -} |
25 | | - |
26 | | -async function getMarkedText(page: import('@playwright/test').Page, markName: string): Promise<string> { |
27 | | - return page.evaluate((name) => { |
28 | | - let text = ''; |
29 | | - const doc = (window as any).editor.state.doc; |
30 | | - |
31 | | - doc.descendants((node: any) => { |
32 | | - if (!node.isText) return; |
33 | | - if (node.marks.some((mark: any) => mark.type.name === name)) { |
34 | | - text += node.text ?? ''; |
35 | | - } |
36 | | - }); |
37 | | - |
38 | | - return text; |
39 | | - }, markName); |
40 | | -} |
41 | | - |
42 | | -async function getSelectedText(page: import('@playwright/test').Page): Promise<string> { |
43 | | - return page.evaluate(() => { |
44 | | - const { from, to, empty } = (window as any).editor.state.selection; |
45 | | - if (empty) return ''; |
46 | | - return (window as any).editor.state.doc.textBetween(from, to); |
47 | | - }); |
48 | | -} |
49 | | - |
50 | | -async function rightClickAtDocPos(page: import('@playwright/test').Page, pos: number) { |
51 | | - const coords = await page.evaluate((p) => { |
52 | | - const editor = (window as any).editor; |
53 | | - const rect = editor?.coordsAtPos?.(p); |
54 | | - if (!rect) return null; |
55 | | - return { |
56 | | - left: Number(rect.left), |
57 | | - right: Number(rect.right), |
58 | | - top: Number(rect.top), |
59 | | - bottom: Number(rect.bottom), |
60 | | - }; |
61 | | - }, pos); |
62 | | - |
63 | | - if (!coords) { |
64 | | - throw new Error(`Could not resolve coordinates for document position ${pos}`); |
65 | | - } |
66 | | - |
67 | | - const x = Math.min(Math.max(coords.left + 1, coords.left), Math.max(coords.right - 1, coords.left + 1)); |
68 | | - const y = (coords.top + coords.bottom) / 2; |
69 | | - await page.mouse.click(x, y, { button: 'right' }); |
70 | | -} |
71 | | - |
72 | 12 | test('toolbar accept partially resolves a tracked insertion and updates the bubble text', async ({ superdoc }) => { |
73 | 13 | await insertTrackedChange(superdoc.page, { from: 1, to: 1, text: TRACK_TEXT }); |
74 | 14 | await superdoc.waitForStable(); |
|
0 commit comments