From 0a09ad590bf4a699fcaf9421da1bf41466d38b8f Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Wed, 2 Sep 2026 08:44:35 +0500 Subject: [PATCH] editor: fix three failing editor tests The list fixtures passed a paragraph into taskItem/checkListItem, which wrap their children in one already. The nested markup reparsed into an extra empty paragraph, so the snapshots never matched. Every other caller passes strings. The image test called insertImage, which has delegated to insertAttachment since 08cf21b0 and is not registered there. It puts the image in as content instead; copying it is what the test is about. --- .../__tests__/check-list-item.test.ts | 3 +-- .../src/extensions/image/tests/image.test.ts | 14 ++++++++------ .../task-item/__tests__/task-item.test.ts | 3 +-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/editor/src/extensions/check-list-item/__tests__/check-list-item.test.ts b/packages/editor/src/extensions/check-list-item/__tests__/check-list-item.test.ts index 738837033..8e3b98abd 100644 --- a/packages/editor/src/extensions/check-list-item/__tests__/check-list-item.test.ts +++ b/packages/editor/src/extensions/check-list-item/__tests__/check-list-item.test.ts @@ -21,7 +21,6 @@ import { describe, expect, test } from "vitest"; import { createEditor, h, - p, checkList, checkListItem } from "../../../../test-utils/index.js"; @@ -36,7 +35,7 @@ describe("check list item", () => { */ test("inline image as first child in check list item", async () => { const el = checkList( - checkListItem([p(["item 1"])]), + checkListItem(["item 1"]), checkListItem([h("img", [], { src: "image.png" })]) ); diff --git a/packages/editor/src/extensions/image/tests/image.test.ts b/packages/editor/src/extensions/image/tests/image.test.ts index 0f328a832..0340cd6a0 100644 --- a/packages/editor/src/extensions/image/tests/image.test.ts +++ b/packages/editor/src/extensions/image/tests/image.test.ts @@ -55,17 +55,19 @@ test("copy image to clipboard when Ctrl+C is pressed on selected image", async ( const editorElement = h("div"); const { editor } = createEditor({ element: editorElement, + // the image is put there as content rather than with `insertImage`, which + // needs the attachment extension: what is under test is the copying + initialContent: h("img", [], { + src: "test.png", + "data-hash": testHash, + "data-mime": "image/png", + "data-filename": "test.png" + }).outerHTML, extensions: { image: ImageNode } }); editor.storage.getAttachmentData = vi.fn().mockResolvedValue(mockImageData); - editor.commands.insertImage({ - src: "test.png", - hash: testHash, - mime: "image/png", - filename: "test.png" - }); editor.commands.setNodeSelection(0); expect(editor.isActive("image")).toBe(true); diff --git a/packages/editor/src/extensions/task-item/__tests__/task-item.test.ts b/packages/editor/src/extensions/task-item/__tests__/task-item.test.ts index c9300c8ff..a7f6f97f1 100644 --- a/packages/editor/src/extensions/task-item/__tests__/task-item.test.ts +++ b/packages/editor/src/extensions/task-item/__tests__/task-item.test.ts @@ -21,7 +21,6 @@ import { describe, expect, test } from "vitest"; import { createEditor, h, - p, taskList, taskItem } from "../../../../test-utils/index.js"; @@ -36,7 +35,7 @@ describe("task list item", () => { */ test("inline image as first child in task list item", async () => { const el = taskList( - taskItem([p(["item 1"])]), + taskItem(["item 1"]), taskItem([h("img", [], { src: "image.png" })]) );