Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {
ITALIC_BUTTON_SELECTOR,
} from "../../utils/const.js";
import { insertHeading, insertParagraph } from "../../utils/copypaste.js";
import { compareDocToSnapshot, focusOnEditor } from "../../utils/editor.js";
import {
compareDocToSnapshot,
focusOnEditor,
moveCursorToBlockEnd,
moveCursorToBlockStart,
} from "../../utils/editor.js";
import { executeSlashCommand } from "../../utils/slashmenu.js";

test.describe.configure({ mode: "serial" });
Expand Down Expand Up @@ -96,7 +101,7 @@ test.describe("Check Keyboard Handlers' Behaviour", () => {
await focusOnEditor(page);
await insertHeading(page, 1);

await page.keyboard.press("Control+ArrowLeft");
await moveCursorToBlockStart(page);
await page.keyboard.press("Backspace");

await compareDocToSnapshot(page, "backspaceStartOfBlock.json");
Expand Down Expand Up @@ -143,7 +148,7 @@ test.describe("Check Keyboard Handlers' Behaviour", () => {
await page.keyboard.press("ArrowUp");
}

await page.keyboard.press("Control+ArrowLeft");
await moveCursorToBlockStart(page);
await page.keyboard.press("Backspace");

await compareDocToSnapshot(page, "backspacePreservesNestedBlocks.json");
Expand Down Expand Up @@ -283,6 +288,7 @@ test.describe("Check Keyboard Handlers' Behaviour", () => {

await page.keyboard.press("ArrowUp");
await page.keyboard.press("ArrowUp");
await moveCursorToBlockEnd(page);
await page.keyboard.press("Delete");

await compareDocToSnapshot(page, "deleteMultipleChildren.json");
Expand All @@ -299,6 +305,7 @@ test.describe("Check Keyboard Handlers' Behaviour", () => {

await page.keyboard.press("ArrowUp");
await page.keyboard.press("ArrowUp");
await moveCursorToBlockEnd(page);
await page.keyboard.press("Delete");

await compareDocToSnapshot(page, "deleteNestedChildren.json");
Expand All @@ -314,6 +321,7 @@ test.describe("Check Keyboard Handlers' Behaviour", () => {
await insertParagraph(page);

await page.keyboard.press("ArrowUp");
await moveCursorToBlockEnd(page);
await page.keyboard.press("Delete");

await compareDocToSnapshot(page, "deleteShallowerBlock.json");
Expand All @@ -335,8 +343,7 @@ test.describe("Check Keyboard Handlers' Behaviour", () => {

await page.keyboard.press("ArrowUp");
await page.keyboard.press("ArrowUp");
await page.keyboard.press("ControlOrMeta+ArrowLeft");
await page.keyboard.press("ControlOrMeta+ArrowRight");
await moveCursorToBlockEnd(page);
await page.keyboard.press("Delete");

await compareDocToSnapshot(page, "deleteShallowerBlockWithChildren.json");
Expand Down
29 changes: 29 additions & 0 deletions tests/src/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,34 @@
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`);

Check failure on line 47 in tests/src/utils/editor.ts

View workflow job for this annotation

GitHub Actions / Playwright Tests - webkit (1/2)

[webkit] › src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts:135:7 › Check Keyboard Handlers' Behaviour › Check Backspace preserves nested blocks

1) [webkit] › src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts:135:7 › Check Keyboard Handlers' Behaviour › Check Backspace preserves nested blocks Error: expect(string).toMatchSnapshot(expected) @@ -18,19 +18,41 @@ "textAlignment": "left" }, "content": [ { "type": "text", - "text": "ParagraphParagraph" + "text": "Paragraph" } ] } ] }, { "type": "blockContainer", "attrs": { + "id": "1" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "backgroundColor": "default", + "textColor": "default", + "textAlignment": "left" + }, + "content": [ + { + "type": "text", + "text": "Paragraph" + } + ] + } + ] + }, + { + "type": "blockContainer", + "attrs": { "id": "2" }, "content": [ { "type": "paragraph", Expected: /__w/BlockNote/BlockNote/tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts-snapshots/backspacePreservesNestedBlocks-json-webkit-linux.json Received: /__w/BlockNote/BlockNote/tests/test-results/keyboardhandlers-keyboardh-494d0-ace-preserves-nested-blocks-webkit/backspacePreservesNestedBlocks-json-actual.json at ../utils/editor.ts:47 45 | // Remove id from docs 46 | const doc = JSON.stringify(await getDoc(page), null, 2); > 47 | expect(doc).toMatchSnapshot(`${name}.json`); | ^ 48 | } 49 | 50 | /** at compareDocToSnapshot (/__w/BlockNote/BlockNote/tests/src/utils/editor.ts:47:15) at /__w/BlockNote/BlockNote/tests/src/end-to-end/keyboardhandlers/keyboardhandlers.test.ts:154:5

Check failure on line 47 in tests/src/utils/editor.ts

View workflow job for this annotation

GitHub Actions / Playwright Tests - chromium (1/2)

[chromium] › src/end-to-end/copypaste/copypaste.test.ts:40:7 › Check Copy/Paste Functionality › Headings should keep formatting

1) [chromium] › src/end-to-end/copypaste/copypaste.test.ts:40:7 › Check Copy/Paste Functionality › Headings should keep formatting Error: expect(string).toMatchSnapshot(expected) @@ -77,11 +77,11 @@ ] }, { "type": "blockContainer", "attrs": { - "id": "4" + "id": "5" }, "content": [ { "type": "heading", "attrs": { @@ -92,20 +92,25 @@ "isToggleable": false }, "content": [ { "type": "text", + "marks": [ + { + "type": "bold" + } + ], "text": "Heading" } ] } ] }, { "type": "blockContainer", "attrs": { - "id": "5" + "id": "6" }, "content": [ { "type": "heading", "attrs": { @@ -116,20 +121,25 @@ "isToggleable": false }, "content": [ { "type": "text", + "marks": [ + { + "type": "bold" + } + ], "text": "Heading" } ] } ] }, { "type": "blockContainer", "attrs": { - "id": "6" + "id": "7" }, "content": [ { "type": "heading", "attrs": { @@ -140,15 +150,36 @@ "isToggleable": false }, "content": [ { "type": "text", + "marks": [ + { + "type": "bold" + } + ], "text": "Heading" } ] } ] + }, + { + "type": "blockContainer", + "attrs": { + "id": "8" + }, + "content": [ + { + "type": "paragraph", + "attrs": { + "backgroundColor": "default", + "textColor": "default", + "textAlignment": "left" + } + } + ] } ] } ] } Expected: /__w/BlockNote/BlockNote/tests/src/end-to-end/copypaste/copypaste.test.ts-snapshots/headings-json-chromium-linux.json Received: /__w/BlockNote/BlockNote/tests/test-results/copypaste-copypaste-Check--b9797-ings-should-keep-formatting-chromium/headings-json-actual.json at ../utils/editor.ts:47 45 | // Remove id from docs 46 | const doc = JSON.stringify(await getDoc(page), null, 2); > 47 | expect(doc).toMatchSnapshot(`${name}.json`); | ^ 48 | } 49 | 50 | /** at compareDocToSnapshot (/__w/BlockNote/BlockNote/tests/src/utils/editor.ts:47:15) at /__w/BlockNote/BlockNote/tests/src/end-to-end/copypaste/copypaste.test.ts:54:5
}

/**
* Programmatically move cursor to end of the current block content.
* This avoids relying on keyboard navigation (ArrowUp/End) which can
* position the cursor incorrectly in WebKit when crossing blocks with
* different indentation levels.
*/
export async function moveCursorToBlockEnd(page: Page) {
await page.evaluate(() => {
const tiptap = (window as any).ProseMirror;
const bnEditor = tiptap.schema.cached.blockNoteEditor;
const block = bnEditor.getTextCursorPosition().block;
bnEditor.setTextCursorPosition(block, "end");
});
}

/**
* Programmatically move cursor to start of the current block content.
* This avoids relying on keyboard navigation which can be unreliable
* in WebKit.
*/
export async function moveCursorToBlockStart(page: Page) {
await page.evaluate(() => {
const tiptap = (window as any).ProseMirror;
const bnEditor = tiptap.schema.cached.blockNoteEditor;
const block = bnEditor.getTextCursorPosition().block;
bnEditor.setTextCursorPosition(block, "start");
});
}
Loading