forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.ts
More file actions
38 lines (33 loc) · 1.1 KB
/
editor.ts
File metadata and controls
38 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Page, expect } from "@playwright/test";
import { EDITOR_SELECTOR } from "./const";
export async function focusOnEditor(page: Page) {
await page.waitForSelector(EDITOR_SELECTOR);
await page.click(EDITOR_SELECTOR);
}
export async function waitForSelectorInEditor(page: Page, selector: string) {
const editor = page.locator(EDITOR_SELECTOR);
await editor.locator(selector).waitFor({
state: "attached",
timeout: 1000,
});
}
export async function getDoc(page: Page) {
const window = await page.evaluateHandle("window");
const doc = await window.evaluate((win) =>
(win as any).ProseMirror.getJSON()
);
return doc;
}
export function removeAttFromDoc(doc: unknown, att: string) {
if (typeof doc !== "object" || doc === null) return;
if (Object.keys(doc).includes(att)) {
delete doc[att];
}
Object.keys(doc).forEach((key) => removeAttFromDoc(doc[key], att));
return doc;
}
export async function compareDocToSnapshot(page: Page, name: string) {
// Remove id from docs
const doc = JSON.stringify(await getDoc(page), null, 2);
expect(doc).toMatchSnapshot(`${name}.json`);
}