Files
buzz-sheet/lib/editor/draft.test.ts
T

41 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { SerializedBlock } from "@/lib/blocks";
import {
createEditorBlock,
duplicateBlock,
moveBlock,
moveBlockTo,
} from "./draft";
const blocks: SerializedBlock[] = ["a", "b", "c"].map((id, sortOrder) => ({
id,
type: "separator",
schemaVersion: 1,
config: {},
sortOrder,
}));
describe("editor block operations", () => {
it("moves blocks with keyboard-friendly relative operations", () => {
expect(moveBlock(blocks, "b", -1).map((block) => block.id)).toEqual(["b", "a", "c"]);
expect(moveBlock(blocks, "a", -1)).toEqual(blocks);
expect(moveBlock(blocks, "b", 1).map((block) => block.sortOrder)).toEqual([0, 1, 2]);
});
it("supports pointer drop targets and duplication with stable order", () => {
expect(moveBlockTo(blocks, "a", "c").map((block) => block.id)).toEqual(["b", "c", "a"]);
expect(duplicateBlock(blocks, "b", "copy").map((block) => block.id)).toEqual(["a", "b", "copy", "c"]);
});
it("requires a configured source for data-backed blocks", () => {
expect(createEditorBlock("comparison-chart")).toBeNull();
expect(createEditorBlock("heading", undefined, "heading-id")).toMatchObject({
id: "heading-id",
type: "heading",
config: { text: "หัวข้อใหม่" },
});
});
});