@uxf/e2e-playwright 12.3.0 → 12.7.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/e2e-playwright",
3
- "version": "12.3.0",
3
+ "version": "12.7.1",
4
4
  "description": "UXF Playwright helpers",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,15 +16,15 @@
16
16
  "author": "UX Fans s.r.o",
17
17
  "license": "MIT",
18
18
  "devDependencies": {
19
- "@playwright/test": "1.62.1",
20
- "@uxf/core": "11.129.0",
21
- "@uxf/ui": "12.3.0",
22
- "dayjs": "^1.11.21"
19
+ "@playwright/test": "1.63.0",
20
+ "@uxf/core": "12.7.0",
21
+ "@uxf/ui": "12.7.1",
22
+ "dayjs": "^1.11.23"
23
23
  },
24
24
  "peerDependencies": {
25
- "@playwright/test": "1.62.1",
26
- "@uxf/core": "11.129.0",
27
- "@uxf/ui": "12.3.0",
28
- "dayjs": "^1.11.21"
25
+ "@playwright/test": "1.63.0",
26
+ "@uxf/core": "12.7.0",
27
+ "@uxf/ui": "12.7.1",
28
+ "dayjs": "^1.11.23"
29
29
  }
30
30
  }
@@ -0,0 +1,11 @@
1
+ import { Page } from "@playwright/test";
2
+ export type EditorSelectionTarget = "all" | "end" | "last-block";
3
+ /**
4
+ * Sets the selection in Slate's model and waits until the DOM shows it.
5
+ *
6
+ * A key that moves the selection (Ctrl+A, End, Shift+Home) is unreliable as test setup: slate-react
7
+ * copies the DOM selection into its model on a throttled `selectionchange`, so the next keystroke or
8
+ * hotkey can act on the old selection, and a render still pending from the previous sync rewrites the
9
+ * DOM from the model and swallows the key.
10
+ */
11
+ export declare function setEditorSelection(page: Page, target: EditorSelectionTarget): Promise<void>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setEditorSelection = setEditorSelection;
4
+ const test_1 = require("@playwright/test");
5
+ /**
6
+ * Sets the selection in Slate's model and waits until the DOM shows it.
7
+ *
8
+ * A key that moves the selection (Ctrl+A, End, Shift+Home) is unreliable as test setup: slate-react
9
+ * copies the DOM selection into its model on a throttled `selectionchange`, so the next keystroke or
10
+ * hotkey can act on the old selection, and a render still pending from the previous sync rewrites the
11
+ * DOM from the model and swallows the key.
12
+ */
13
+ async function setEditorSelection(page, target) {
14
+ const applyAndCheckSync = (applyTarget) => page.evaluate((applied) => {
15
+ var _a, _b, _c, _d;
16
+ // Slate's editor object is only reachable through the React tree of its editable.
17
+ const element = document.querySelector("[data-slate-editor]");
18
+ const fiberKey = element ? Object.keys(element).find((key) => key.startsWith("__reactFiber$")) : undefined;
19
+ let fiber = fiberKey ? ((_a = element[fiberKey]) !== null && _a !== void 0 ? _a : null) : null;
20
+ while (fiber && !((_c = (_b = fiber.memoizedProps) === null || _b === void 0 ? void 0 : _b.editor) === null || _c === void 0 ? void 0 : _c.children)) {
21
+ fiber = fiber.return;
22
+ }
23
+ const editor = (_d = fiber === null || fiber === void 0 ? void 0 : fiber.memoizedProps) === null || _d === void 0 ? void 0 : _d.editor;
24
+ if (!editor) {
25
+ return false;
26
+ }
27
+ if (applied === "all") {
28
+ editor.tf.select([]);
29
+ }
30
+ else if (applied === "end") {
31
+ editor.tf.collapse({ edge: "end" });
32
+ }
33
+ else if (applied === "last-block") {
34
+ editor.tf.select([editor.children.length - 1]);
35
+ }
36
+ const domSelection = document.getSelection();
37
+ const fromDom = domSelection
38
+ ? editor.api.toSlateRange(domSelection, { exactMatch: false, suppressThrow: true })
39
+ : null;
40
+ return Boolean(editor.selection) && JSON.stringify(fromDom) === JSON.stringify(editor.selection);
41
+ }, applyTarget);
42
+ await applyAndCheckSync(target);
43
+ await test_1.expect.poll(() => applyAndCheckSync(null)).toBe(true);
44
+ }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const test_1 = require("@playwright/test");
4
+ const editor_selection_1 = require("./editor-selection");
4
5
  const EDITABLE = ".uxf-wysiwyg__editable";
5
6
  /**
6
7
  * Keyboard shortcuts, which nothing else covers: the toolbar tests click buttons, and a shortcut can be
@@ -14,9 +15,10 @@ const EDITABLE = ".uxf-wysiwyg__editable";
14
15
  /** Replaces the document with `text` and leaves it selected. */
15
16
  async function selectFresh(page, text) {
16
17
  await page.locator(EDITABLE).click();
17
- await page.keyboard.press("ControlOrMeta+a");
18
+ await (0, editor_selection_1.setEditorSelection)(page, "all");
18
19
  await page.keyboard.type(text);
19
- await page.keyboard.press("ControlOrMeta+a");
20
+ await (0, test_1.expect)(page.locator(EDITABLE)).toHaveText(text);
21
+ await (0, editor_selection_1.setEditorSelection)(page, "all");
20
22
  }
21
23
  const MARKS = [
22
24
  ["bold", "ControlOrMeta+b", "uxf-wysiwyg__element-bold"],
@@ -43,7 +45,7 @@ test_1.test.describe("wysiwyg hotkeys", () => {
43
45
  (0, test_1.test)("ControlOrMeta+Enter leaves the current block", async ({ page }) => {
44
46
  await page.goto("/examples/wysiwyg/playground");
45
47
  await selectFresh(page, "prvni");
46
- await page.keyboard.press("ArrowRight");
48
+ await (0, editor_selection_1.setEditorSelection)(page, "end");
47
49
  await page.keyboard.press("ControlOrMeta+Enter");
48
50
  await (0, test_1.expect)(page.locator(`${EDITABLE} [data-slate-node="element"]`)).not.toHaveCount(1);
49
51
  });
@@ -56,7 +58,7 @@ test_1.test.describe("wysiwyg hotkeys", () => {
56
58
  (0, test_1.test)("ControlOrMeta+Z and ControlOrMeta+Shift+Z walk history", async ({ page }) => {
57
59
  await page.goto("/examples/wysiwyg/playground");
58
60
  await selectFresh(page, "puvodni");
59
- await page.keyboard.press("End");
61
+ await (0, editor_selection_1.setEditorSelection)(page, "end");
60
62
  await page.keyboard.type(" pridane");
61
63
  await page.keyboard.press("ControlOrMeta+z");
62
64
  await (0, test_1.expect)(page.locator(EDITABLE)).not.toContainText("pridane");
@@ -1,26 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const test_1 = require("@playwright/test");
4
+ const editor_selection_1 = require("./editor-selection");
4
5
  const PLAYGROUND = "/examples/wysiwyg/playground";
5
6
  const EDITABLE = ".uxf-wysiwyg__editable";
6
7
  /** What jsdom cannot see: which element a toolbar button produces, and whether the popovers work. */
7
8
  async function openPlayground(page) {
8
9
  await page.goto(PLAYGROUND);
9
10
  await (0, test_1.expect)(page.locator(EDITABLE)).toBeVisible();
10
- // The editable is in the DOM before the toolbar is, and the toolbar needs the editor from
11
- // context - so waiting for a toolbar button is what says the editor is actually interactive.
12
- // Without it, keystrokes sent under parallel load can land before Plate is listening.
13
- await (0, test_1.expect)(page.locator(".uxf-wysiwyg__toolbar-button").first()).toBeVisible();
14
11
  }
15
12
  /** Replaces the document with a single paragraph holding `text`, and leaves it selected. */
16
13
  async function typeFresh(page, text) {
17
14
  await page.locator(EDITABLE).click();
18
- await page.keyboard.press("ControlOrMeta+a");
15
+ await (0, editor_selection_1.setEditorSelection)(page, "all");
19
16
  await page.keyboard.type(text);
20
17
  // Confirm the text landed before the test acts on it; a dropped keystroke otherwise surfaces
21
18
  // as a confusing failure several steps later.
22
- await (0, test_1.expect)(page.locator(EDITABLE)).toContainText(text);
23
- await page.keyboard.press("ControlOrMeta+a");
19
+ await (0, test_1.expect)(page.locator(EDITABLE)).toHaveText(text);
20
+ await (0, editor_selection_1.setEditorSelection)(page, "all");
24
21
  }
25
22
  function toolbarButton(page, modifier) {
26
23
  return page.locator(`.uxf-wysiwyg__toolbar-button-${modifier}`).first();
@@ -66,7 +63,7 @@ test_1.test.describe("wysiwyg blocks", () => {
66
63
  // Enter splits the quote, and a second Enter on the empty line leaves it. Click the quote
67
64
  // itself rather than the editable: a click anywhere else lands the caret in another block.
68
65
  await page.locator(`${EDITABLE} .uxf-wysiwyg__element-blockquote`).click();
69
- await page.keyboard.press("End");
66
+ await (0, editor_selection_1.setEditorSelection)(page, "end");
70
67
  await page.keyboard.press("Enter");
71
68
  await (0, test_1.expect)(page.locator(`${EDITABLE} .uxf-wysiwyg__element-blockquote`)).toHaveCount(2);
72
69
  await page.keyboard.press("Enter");
@@ -183,9 +180,9 @@ test_1.test.describe("wysiwyg floating link placement", () => {
183
180
  await openPlayground(page);
184
181
  // Fill the document so the caret ends up near the bottom of a short viewport.
185
182
  await page.locator(EDITABLE).click();
186
- await page.keyboard.press("ControlOrMeta+a");
183
+ await (0, editor_selection_1.setEditorSelection)(page, "all");
187
184
  await page.keyboard.type(`${Array.from({ length: 12 }, (_, i) => `řádek ${i}`).join("\n")}\nodkaz`);
188
- await page.keyboard.press("Shift+Home");
185
+ await (0, editor_selection_1.setEditorSelection)(page, "last-block");
189
186
  const caret = await page.locator(`${EDITABLE} [data-slate-node="element"]`).last().boundingBox();
190
187
  await toolbarButton(page, "link").click();
191
188
  const form = page.locator(".uxf-wysiwyg__floating-link-insert__form");
@@ -216,7 +213,7 @@ test_1.test.describe("wysiwyg history", () => {
216
213
  (0, test_1.test)("undo and redo walk the edit back and forward", async ({ page }) => {
217
214
  await openPlayground(page);
218
215
  await typeFresh(page, "původní");
219
- await page.keyboard.press("End");
216
+ await (0, editor_selection_1.setEditorSelection)(page, "end");
220
217
  await page.keyboard.type(" a přidané");
221
218
  await (0, test_1.expect)(page.locator(EDITABLE)).toContainText("a přidané");
222
219
  const group = page.locator(".uxf-wysiwyg__toolbar-button-group-undo-redo");