@platejs/test 0.0.0-stage → 54.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +283 -2
- package/dist/browser/index.d.ts +25 -0
- package/dist/browser/index.js +69 -0
- package/dist/feature-contracts-BhHdrzuI.js +32 -0
- package/dist/feature-contracts-Dwvvzqfa.d.ts +24 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/playwright/index.d.ts +1586 -0
- package/dist/playwright/index.js +6170 -0
- package/dist/proof/index.d.ts +250 -0
- package/dist/proof/index.js +634 -0
- package/dist/react/index.d.ts +50 -0
- package/dist/react/index.js +141 -0
- package/dist/zero-width-BGyZc7Mb.d.ts +11 -0
- package/package.json +120 -3
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { act, fireEvent, render } from "@testing-library/react";
|
|
2
|
+
import { parseHotkey } from "is-hotkey";
|
|
3
|
+
import { EditorContent, EditorRoot, createEditor } from "platejs/react";
|
|
4
|
+
import React from "react";
|
|
5
|
+
//#region src/react/PlateTest.tsx
|
|
6
|
+
function EditorTest({ editableProps, editor, variant = "wordProcessor", ...props }) {
|
|
7
|
+
return /* @__PURE__ */ React.createElement(EditorRoot, {
|
|
8
|
+
...props,
|
|
9
|
+
editor
|
|
10
|
+
}, /* @__PURE__ */ React.createElement(EditorContent, {
|
|
11
|
+
"data-variant": variant,
|
|
12
|
+
autoFocus: true,
|
|
13
|
+
...editableProps
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/react/createPlateTestEditor.ts
|
|
18
|
+
const fireBeforeInput = (element, init) => {
|
|
19
|
+
fireEvent(element, new InputEvent("beforeinput", {
|
|
20
|
+
bubbles: true,
|
|
21
|
+
cancelable: true,
|
|
22
|
+
...init
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
const createTestEditor = async (options, harnessOptions = {}) => {
|
|
26
|
+
const { componentProps = {}, debug = false } = harnessOptions;
|
|
27
|
+
const editor = createEditor(options);
|
|
28
|
+
const editable = React.createRef();
|
|
29
|
+
const callerRef = componentProps.editableProps?.ref;
|
|
30
|
+
const plateProps = {
|
|
31
|
+
...componentProps,
|
|
32
|
+
editableProps: {
|
|
33
|
+
...componentProps.editableProps,
|
|
34
|
+
ref: (node) => {
|
|
35
|
+
editable.current = node;
|
|
36
|
+
if (typeof callerRef === "function") return callerRef(node);
|
|
37
|
+
if (callerRef) callerRef.current = node;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
editor,
|
|
41
|
+
suppressInstanceWarning: true
|
|
42
|
+
};
|
|
43
|
+
const rendered = render(React.createElement(EditorTest, plateProps));
|
|
44
|
+
await act(async () => rendered);
|
|
45
|
+
const element = editable.current;
|
|
46
|
+
if (!element) throw new Error("createTestEditor: EditorTest did not mount its editable");
|
|
47
|
+
Object.defineProperty(element, "isContentEditable", {
|
|
48
|
+
configurable: true,
|
|
49
|
+
value: true
|
|
50
|
+
});
|
|
51
|
+
if (debug) editor.subscribeCommit((commit) => {
|
|
52
|
+
console.info("EDITOR COMMIT", JSON.stringify(commit, null, 2));
|
|
53
|
+
});
|
|
54
|
+
const triggerKeyboardEvent = async (hotkey) => act(async () => {
|
|
55
|
+
const eventProps = parseHotkey(hotkey);
|
|
56
|
+
const eventInit = {
|
|
57
|
+
bubbles: true,
|
|
58
|
+
key: hotkey.split("+").at(-1),
|
|
59
|
+
...eventProps
|
|
60
|
+
};
|
|
61
|
+
Reflect.set(eventInit, "keyCode", Reflect.get(eventProps, "which"));
|
|
62
|
+
fireEvent(element, new KeyboardEvent("keydown", eventInit));
|
|
63
|
+
});
|
|
64
|
+
const type = async (text) => act(async () => {
|
|
65
|
+
fireBeforeInput(element, {
|
|
66
|
+
data: text,
|
|
67
|
+
inputType: "insertText"
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
const paste = async (payload, pasteOptions = {}) => act(async () => {
|
|
71
|
+
const types = pasteOptions.types ?? ["text/html"];
|
|
72
|
+
const event = new Event("paste", {
|
|
73
|
+
bubbles: true,
|
|
74
|
+
cancelable: true,
|
|
75
|
+
composed: true
|
|
76
|
+
});
|
|
77
|
+
event.clipboardData = {
|
|
78
|
+
getData: () => payload,
|
|
79
|
+
types
|
|
80
|
+
};
|
|
81
|
+
fireEvent(element, event);
|
|
82
|
+
});
|
|
83
|
+
const optionalHistoryEditor = editor;
|
|
84
|
+
return [
|
|
85
|
+
editor,
|
|
86
|
+
{
|
|
87
|
+
deleteBackward: async () => act(async () => {
|
|
88
|
+
fireBeforeInput(element, { inputType: "deleteContentBackward" });
|
|
89
|
+
}),
|
|
90
|
+
deleteEntireSoftline: async () => act(async () => {
|
|
91
|
+
fireBeforeInput(element, { inputType: "deleteEntireSoftLine" });
|
|
92
|
+
}),
|
|
93
|
+
deleteForward: async () => act(async () => {
|
|
94
|
+
fireBeforeInput(element, { inputType: "deleteContentForward" });
|
|
95
|
+
}),
|
|
96
|
+
deleteHardLineBackward: async () => act(async () => {
|
|
97
|
+
fireBeforeInput(element, { inputType: "deleteHardLineBackward" });
|
|
98
|
+
}),
|
|
99
|
+
deleteHardLineForward: async () => act(async () => {
|
|
100
|
+
fireBeforeInput(element, { inputType: "deleteHardLineForward" });
|
|
101
|
+
}),
|
|
102
|
+
deleteSoftLineBackward: async () => act(async () => {
|
|
103
|
+
fireBeforeInput(element, { inputType: "deleteSoftLineBackward" });
|
|
104
|
+
}),
|
|
105
|
+
deleteSoftLineForward: async () => act(async () => {
|
|
106
|
+
fireBeforeInput(element, { inputType: "deleteSoftLineForward" });
|
|
107
|
+
}),
|
|
108
|
+
deleteWordBackward: async () => act(async () => {
|
|
109
|
+
fireBeforeInput(element, { inputType: "deleteWordBackward" });
|
|
110
|
+
}),
|
|
111
|
+
deleteWordForward: async () => act(async () => {
|
|
112
|
+
fireBeforeInput(element, { inputType: "deleteWordForward" });
|
|
113
|
+
}),
|
|
114
|
+
paste,
|
|
115
|
+
pressEnter: async () => {
|
|
116
|
+
await triggerKeyboardEvent("Enter");
|
|
117
|
+
await act(async () => {
|
|
118
|
+
fireBeforeInput(element, { inputType: "insertParagraph" });
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
redo: async () => {
|
|
122
|
+
optionalHistoryEditor.redo?.();
|
|
123
|
+
},
|
|
124
|
+
rerender: () => {
|
|
125
|
+
rendered.rerender(React.createElement(EditorTest, plateProps));
|
|
126
|
+
},
|
|
127
|
+
selectAll: async () => act(async () => {
|
|
128
|
+
editor.update.selection.set([]);
|
|
129
|
+
}),
|
|
130
|
+
triggerKeyboardEvent,
|
|
131
|
+
type,
|
|
132
|
+
typeSpace: () => type(" "),
|
|
133
|
+
undo: async () => {
|
|
134
|
+
optionalHistoryEditor.undo?.();
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
rendered
|
|
138
|
+
];
|
|
139
|
+
};
|
|
140
|
+
//#endregion
|
|
141
|
+
export { EditorTest, createTestEditor };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/browser/zero-width.d.ts
|
|
2
|
+
/** Rendered zero-width placeholder marker shape. */
|
|
3
|
+
type PlaceholderShape = {
|
|
4
|
+
hasBr: boolean;
|
|
5
|
+
hasFEFF: boolean;
|
|
6
|
+
kind: string | null;
|
|
7
|
+
};
|
|
8
|
+
/** Inspect the rendered shape of a editor zero-width placeholder element. */
|
|
9
|
+
declare const inspectZeroWidthPlaceholder: (element: Element | null) => PlaceholderShape;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { inspectZeroWidthPlaceholder as n, PlaceholderShape as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,123 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platejs/test",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "54.0.0-beta.2",
|
|
4
|
+
"description": "Headless, React, browser, Playwright, and proof utilities for Plate editors.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"editor",
|
|
7
|
+
"platejs",
|
|
8
|
+
"playwright",
|
|
9
|
+
"react",
|
|
10
|
+
"testing"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://platejs.org",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/udecode/plate/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/udecode/plate.git",
|
|
20
|
+
"directory": "packages/test"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/**/*"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./browser": {
|
|
37
|
+
"types": "./dist/browser/index.d.ts",
|
|
38
|
+
"import": "./dist/browser/index.js",
|
|
39
|
+
"default": "./dist/browser/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./playwright": {
|
|
42
|
+
"types": "./dist/playwright/index.d.ts",
|
|
43
|
+
"import": "./dist/playwright/index.js",
|
|
44
|
+
"default": "./dist/playwright/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./proof": {
|
|
47
|
+
"types": "./dist/proof/index.d.ts",
|
|
48
|
+
"import": "./dist/proof/index.js",
|
|
49
|
+
"default": "./dist/proof/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./react": {
|
|
52
|
+
"types": "./dist/react/index.d.ts",
|
|
53
|
+
"import": "./dist/react/index.js",
|
|
54
|
+
"default": "./dist/react/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./package.json": "./package.json"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"is-hotkey": "^0.2.0"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@playwright/test": "1.61.0",
|
|
66
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
67
|
+
"@testing-library/react": "16.3.0",
|
|
68
|
+
"@types/node": "24.12.0",
|
|
69
|
+
"@types/react": "19.2.7",
|
|
70
|
+
"@vitest/browser-playwright": "^4.1.0",
|
|
71
|
+
"playwright": "^1.58.2",
|
|
72
|
+
"react": "19.2.8",
|
|
73
|
+
"react-dom": "19.2.8",
|
|
74
|
+
"vite": "^7.1.12",
|
|
75
|
+
"vitest": "^4.1.0",
|
|
76
|
+
"platejs": "^54.0.0-beta.2"
|
|
77
|
+
},
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"@playwright/test": ">=1.52.0",
|
|
80
|
+
"@testing-library/react": ">=16.0.0",
|
|
81
|
+
"platejs": ">=54.0.0-beta.2",
|
|
82
|
+
"react": ">=19.2.0",
|
|
83
|
+
"react-dom": ">=19.2.0"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"@playwright/test": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"@testing-library/react": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"react": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"react-dom": {
|
|
96
|
+
"optional": true
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"scripts": {
|
|
100
|
+
"brl": "echo 'No barrels to generate'",
|
|
101
|
+
"build": "tsdown --config tsdown.config.mts --log-level warn",
|
|
102
|
+
"clean": "rimraf dist lib",
|
|
103
|
+
"lint": "node ../../tooling/scripts/run-entrypoint-package-task.mjs @platejs/test lint",
|
|
104
|
+
"lint:fix": "node ../../tooling/scripts/plate-pkg.cjs p:lint:fix",
|
|
105
|
+
"lint:partition:browser": "node ../../tooling/scripts/run-entrypoint-task.mjs lint @platejs/test browser",
|
|
106
|
+
"lint:partition:device": "node ../../tooling/scripts/run-entrypoint-task.mjs lint @platejs/test device",
|
|
107
|
+
"lint:partition:playwright": "node ../../tooling/scripts/run-entrypoint-task.mjs lint @platejs/test playwright",
|
|
108
|
+
"lint:partition:proof": "node ../../tooling/scripts/run-entrypoint-task.mjs lint @platejs/test proof",
|
|
109
|
+
"lint:partition:react": "node ../../tooling/scripts/run-entrypoint-task.mjs lint @platejs/test react",
|
|
110
|
+
"lint:partition:root": "node ../../tooling/scripts/run-entrypoint-task.mjs lint @platejs/test root",
|
|
111
|
+
"test": "node ../../tooling/scripts/run-entrypoint-package-task.mjs @platejs/test test",
|
|
112
|
+
"test:dom": "vitest run --config ./vitest.config.ts --project browser",
|
|
113
|
+
"test:node": "bun test --preload ../../config/plite-source-test-setup.ts test/node test/proof",
|
|
114
|
+
"test:partition:browser": "node ../../tooling/scripts/run-entrypoint-task.mjs test @platejs/test browser",
|
|
115
|
+
"test:partition:proof": "node ../../tooling/scripts/run-entrypoint-task.mjs test @platejs/test proof",
|
|
116
|
+
"test:partition:react": "node ../../tooling/scripts/run-entrypoint-task.mjs test @platejs/test react",
|
|
117
|
+
"test:partition:root": "node ../../tooling/scripts/run-entrypoint-task.mjs test @platejs/test root",
|
|
118
|
+
"test:proof": "bun test --preload ../../config/plite-source-test-setup.ts test/proof/raw-mobile-proof.test.ts test/proof/scenario.test.ts",
|
|
119
|
+
"test:react": "bun test --preload ../../config/plite-source-test-setup.ts test/react",
|
|
120
|
+
"test:selection": "vitest run --config ./vitest.config.ts --project browser test/browser/selection.browser.test.ts",
|
|
121
|
+
"typecheck": "node ../../tooling/scripts/typecheck.mjs @platejs/test"
|
|
122
|
+
}
|
|
6
123
|
}
|