텍스트/버튼/이미지/섹션 블록 타입 확장 및 에디터 UI 연동

This commit is contained in:
2025-11-18 06:26:02 +09:00
parent 4b00e9a3f9
commit d21252eb1f
4 changed files with 474 additions and 98 deletions
+39 -3
View File
@@ -1,5 +1,9 @@
import { describe, it, expect } from "vitest";
import { createEditorStore } from "@/features/editor/state/editorStore";
import {
createEditorStore,
type TextBlockProps,
type ButtonBlockProps,
} from "@/features/editor/state/editorStore";
// 에디터 상태 스토어에 대한 첫 TDD: 텍스트 블록 추가
@@ -13,7 +17,8 @@ describe("editorStore", () => {
expect(blocks).toHaveLength(1);
expect(blocks[0].type).toBe("text");
expect(blocks[0].props.text).toBe("새 텍스트");
const textProps = blocks[0].props as TextBlockProps;
expect(textProps.text).toBe("새 텍스트");
expect(selectedBlockId).toBe(blocks[0].id);
});
@@ -39,6 +44,37 @@ describe("editorStore", () => {
blocks = store.getState().blocks;
expect(blocks.map((b) => b.id)).toEqual([bId, aId, cId]);
expect(blocks.map((b) => b.props.text)).toEqual(["블록 B", "블록 A", "블록 C"]);
expect(blocks.map((b) => (b.props as TextBlockProps).text)).toEqual([
"블록 B",
"블록 A",
"블록 C",
]);
});
it("버튼 블록을 추가하고 라벨/링크를 업데이트할 수 있어야 한다", () => {
const store = createEditorStore();
// 텍스트 블록 외에 버튼 블록을 추가하는 액션을 호출한다고 가정한다.
store.getState().addButtonBlock();
const { blocks, selectedBlockId } = store.getState();
expect(blocks).toHaveLength(1);
expect(blocks[0].type).toBe("button");
const buttonProps = blocks[0].props as ButtonBlockProps;
expect(buttonProps.label).toBe("버튼");
expect(buttonProps.href).toBe("#");
// 버튼 라벨과 링크를 업데이트한다.
store.getState().updateBlock(blocks[0].id, {
label: "자세히 보기",
href: "https://example.com",
} as any);
const { blocks: updatedBlocks } = store.getState();
const updatedButtonProps = updatedBlocks[0].props as ButtonBlockProps;
expect(updatedButtonProps.label).toBe("자세히 보기");
expect(updatedButtonProps.href).toBe("https://example.com");
expect(selectedBlockId).toBe(updatedBlocks[0].id);
});
});