forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTestEditor.ts
More file actions
62 lines (56 loc) · 1.47 KB
/
createTestEditor.ts
File metadata and controls
62 lines (56 loc) · 1.47 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {
BlockNoteEditor,
BlockNoteSchema,
BlockSchema,
createCodeBlockSpec,
InlineContentSchema,
StyleSchema,
uploadToTmpFilesDotOrg_DEV_ONLY,
} from "@blocknote/core";
import { afterAll, beforeAll } from "vitest";
export const createTestEditor = <
B extends BlockSchema,
I extends InlineContentSchema,
S extends StyleSchema,
>(
schema: BlockNoteSchema<B, I, S>,
): (() => BlockNoteEditor<B, I, S>) => {
let editor: BlockNoteEditor<B, I, S>;
const div = document.createElement("div");
beforeAll(async () => {
(window as any).__TEST_OPTIONS = (window as any).__TEST_OPTIONS || {};
editor = BlockNoteEditor.create({
schema: schema.extend({
blockSpecs: {
codeBlock: createCodeBlockSpec({
supportedLanguages: {
javascript: {
name: "JavaScript",
aliases: ["js"],
},
python: {
name: "Python",
aliases: ["py"],
},
},
}),
},
}),
tables: {
splitCells: true,
cellBackgroundColor: true,
cellTextColor: true,
headers: true,
},
trailingBlock: false,
uploadFile: uploadToTmpFilesDotOrg_DEV_ONLY,
}) as any;
editor.mount(div);
});
afterAll(() => {
editor._tiptapEditor.destroy();
editor = undefined as any;
delete (window as Window & { __TEST_OPTIONS?: any }).__TEST_OPTIONS;
});
return () => editor;
};