editor: add test case to assert migration of old inline images in outline list item

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2025-10-30 12:53:21 +05:00
parent 78e4672871
commit 1f47df0f45
2 changed files with 30 additions and 0 deletions

View File

@@ -128,3 +128,5 @@ exports[`outline list item > code block in outline list item 1`] = `
"type": "doc",
}
`;
exports[`outline list item > inline image as first child in the old outline list item 1`] = `"<ul data-type="outlineList"><li data-type="outlineListItem"><p data-spacing="double">item 1</p></li><li data-type="outlineListItem"><p data-spacing="double"></p><img src="image.png" data-aspect-ratio="1"></li></ul>"`;

View File

@@ -28,6 +28,8 @@ import { test, expect, describe, beforeAll, vi } from "vitest";
import { OutlineList } from "../../outline-list/outline-list.js";
import { OutlineListItem } from "../outline-list-item.js";
import { CodeBlock } from "../../code-block/code-block.js";
import { Paragraph } from "../../paragraph/paragraph.js";
import { ImageNode } from "../../image/image.js";
describe("outline list item", () => {
beforeAll(() => {
@@ -70,4 +72,30 @@ describe("outline list item", () => {
expect(editor.getJSON()).toMatchSnapshot();
});
/**
* Two changes happened:
* 1. Images were converted from inline nodes to block nodes (https://github.com/streetwriters/notesnook/pull/8563)
* 2. Outline list item's `content` schema was changed from `paragraph + list?` to `block+` to `paragraph block*` (https://github.com/streetwriters/notesnook/pull/8772 and https://github.com/streetwriters/notesnook/commit/0b943d8ecdf04fd7d996fd0a4b1d62ec9569f071)
*
* In the old editor, it was possible to have an inline image as the first item in the outline list item, but based on the new schema it is not possible anymore. So the editor should insert an empty paragraph before the image.
*/
test("inline image as first child in the old outline list item", async () => {
const el = outlineList(
outlineListItem(["item 1"]),
outlineListItem([h("img", [], { src: "image.png" })])
);
const { editor } = createEditor({
initialContent: el.outerHTML,
extensions: {
outlineList: OutlineList,
outlineListItem: OutlineListItem,
paragraph: Paragraph,
image: ImageNode
}
});
expect(editor.getHTML()).toMatchSnapshot();
});
});