텍스트 스타일 및 프리뷰 렌더링 정리
This commit is contained in:
@@ -636,6 +636,154 @@ describe("editorStore", () => {
|
||||
expect(t1.id).not.toBe(t2.id);
|
||||
expect(t1.props).toEqual(t2.props);
|
||||
expect(t2.sectionId).toBe(t1.sectionId);
|
||||
expect(t2.columnId).toBe(t1.columnId);
|
||||
});
|
||||
|
||||
it("폼 입력 블록을 추가하면 기본 label/formFieldName 과 함께 루트에 추가되고 선택되어야 한다", () => {
|
||||
const store = createEditorStore();
|
||||
|
||||
const stateAny = store.getState() as any;
|
||||
stateAny.addFormInputBlock();
|
||||
|
||||
const { blocks, selectedBlockId } = store.getState();
|
||||
|
||||
expect(blocks).toHaveLength(1);
|
||||
expect(blocks[0].type).toBe("formInput");
|
||||
|
||||
const inputProps = blocks[0].props as any;
|
||||
expect(typeof inputProps.label).toBe("string");
|
||||
expect(inputProps.label.length).toBeGreaterThan(0);
|
||||
// 기본 formFieldName 은 label 을 기반으로 한 키거나, 최소한 truthy 여야 한다고 가정
|
||||
expect(typeof inputProps.formFieldName).toBe("string");
|
||||
expect(inputProps.formFieldName.length).toBeGreaterThan(0);
|
||||
|
||||
// 루트에 추가된 경우 sectionId/columnId 는 null 이어야 한다.
|
||||
expect((blocks[0] as any).sectionId).toBeNull();
|
||||
expect((blocks[0] as any).columnId).toBeNull();
|
||||
|
||||
expect(selectedBlockId).toBe(blocks[0].id);
|
||||
});
|
||||
|
||||
it("폼 블록의 기본 컨트롤러 속성(fieldIds/submitButtonId)이 올바르게 초기화되어야 한다", () => {
|
||||
const store = createEditorStore();
|
||||
|
||||
const stateAny = store.getState() as any;
|
||||
stateAny.addFormBlock();
|
||||
|
||||
const { blocks } = store.getState();
|
||||
|
||||
expect(blocks).toHaveLength(1);
|
||||
expect(blocks[0].type).toBe("form");
|
||||
|
||||
const formProps = blocks[0].props as any;
|
||||
// 기본적으로 fieldIds 는 빈 배열, submitButtonId 는 undefined 로 본다.
|
||||
expect(Array.isArray(formProps.fieldIds) || formProps.fieldIds === undefined).toBe(true);
|
||||
if (Array.isArray(formProps.fieldIds)) {
|
||||
expect(formProps.fieldIds).toHaveLength(0);
|
||||
}
|
||||
expect(formProps.submitButtonId === undefined || formProps.submitButtonId === null).toBe(true);
|
||||
});
|
||||
|
||||
it("폼 셀렉트 블록을 추가하면 기본 label/formFieldName/options 와 함께 루트에 추가되어야 한다", () => {
|
||||
const store = createEditorStore();
|
||||
|
||||
const stateAny = store.getState() as any;
|
||||
// 아직 구현되지 않은 액션이므로 실패 상태에서 시작
|
||||
stateAny.addFormSelectBlock();
|
||||
|
||||
const { blocks, selectedBlockId } = store.getState();
|
||||
|
||||
expect(blocks).toHaveLength(1);
|
||||
expect(blocks[0].type).toBe("formSelect");
|
||||
|
||||
const selectProps = blocks[0].props as any;
|
||||
expect(typeof selectProps.label).toBe("string");
|
||||
expect(selectProps.label.length).toBeGreaterThan(0);
|
||||
expect(typeof selectProps.formFieldName).toBe("string");
|
||||
expect(selectProps.formFieldName.length).toBeGreaterThan(0);
|
||||
expect(Array.isArray(selectProps.options)).toBe(true);
|
||||
expect(selectProps.options.length).toBeGreaterThan(0);
|
||||
|
||||
// 루트에 추가된 경우 sectionId/columnId 는 null 이어야 한다.
|
||||
expect((blocks[0] as any).sectionId).toBeNull();
|
||||
expect((blocks[0] as any).columnId).toBeNull();
|
||||
|
||||
expect(selectedBlockId).toBe(blocks[0].id);
|
||||
});
|
||||
|
||||
it("폼 체크박스 블록을 추가하면 기본 groupLabel/formFieldName 과 함께 루트에 추가되어야 한다", () => {
|
||||
const store = createEditorStore();
|
||||
|
||||
const stateAny = store.getState() as any;
|
||||
stateAny.addFormCheckboxBlock();
|
||||
|
||||
const { blocks, selectedBlockId } = store.getState();
|
||||
|
||||
expect(blocks).toHaveLength(1);
|
||||
expect(blocks[0].type).toBe("formCheckbox");
|
||||
|
||||
const checkboxProps = blocks[0].props as any;
|
||||
expect(typeof checkboxProps.groupLabel).toBe("string");
|
||||
expect(checkboxProps.groupLabel.length).toBeGreaterThan(0);
|
||||
expect(typeof checkboxProps.formFieldName).toBe("string");
|
||||
expect(checkboxProps.formFieldName.length).toBeGreaterThan(0);
|
||||
// 그룹 타이틀의 모드는 존재하면 기본값이 text 여야 한다.
|
||||
expect(checkboxProps.groupLabelMode ?? "text").toBe("text");
|
||||
|
||||
expect((blocks[0] as any).sectionId).toBeNull();
|
||||
expect((blocks[0] as any).columnId).toBeNull();
|
||||
|
||||
expect(selectedBlockId).toBe(blocks[0].id);
|
||||
});
|
||||
|
||||
it("폼 라디오 그룹 블록을 추가하면 groupLabel/formFieldName/options 와 함께 루트에 추가되어야 한다", () => {
|
||||
const store = createEditorStore();
|
||||
|
||||
const stateAny = store.getState() as any;
|
||||
stateAny.addFormRadioBlock();
|
||||
|
||||
const { blocks, selectedBlockId } = store.getState();
|
||||
|
||||
expect(blocks).toHaveLength(1);
|
||||
expect(blocks[0].type).toBe("formRadio");
|
||||
|
||||
const radioProps = blocks[0].props as any;
|
||||
expect(typeof radioProps.groupLabel).toBe("string");
|
||||
expect(radioProps.groupLabel.length).toBeGreaterThan(0);
|
||||
expect(typeof radioProps.formFieldName).toBe("string");
|
||||
expect(radioProps.formFieldName.length).toBeGreaterThan(0);
|
||||
expect(Array.isArray(radioProps.options)).toBe(true);
|
||||
expect(radioProps.options.length).toBeGreaterThan(0);
|
||||
// 라디오 그룹 타이틀 모드도 존재한다면 기본값은 text 로 본다.
|
||||
expect(radioProps.groupLabelMode ?? "text").toBe("text");
|
||||
|
||||
expect((blocks[0] as any).sectionId).toBeNull();
|
||||
expect((blocks[0] as any).columnId).toBeNull();
|
||||
|
||||
expect(selectedBlockId).toBe(blocks[0].id);
|
||||
});
|
||||
|
||||
it("폼 블록의 fieldIds/submitButtonId 를 updateBlock 으로 업데이트할 수 있어야 한다", () => {
|
||||
const store = createEditorStore();
|
||||
|
||||
const stateAny = store.getState() as any;
|
||||
stateAny.addFormBlock();
|
||||
|
||||
const { blocks } = store.getState();
|
||||
const formBlock = blocks[0];
|
||||
|
||||
// 임의의 필드/버튼 id 설정
|
||||
const fieldIds = ["field_1", "field_2"];
|
||||
const submitButtonId = "btn_submit";
|
||||
|
||||
store.getState().updateBlock(formBlock.id, {
|
||||
fieldIds,
|
||||
submitButtonId,
|
||||
} as any);
|
||||
|
||||
const { blocks: updatedBlocks } = store.getState();
|
||||
const updatedFormProps = updatedBlocks[0].props as any;
|
||||
|
||||
expect(updatedFormProps.fieldIds).toEqual(fieldIds);
|
||||
expect(updatedFormProps.submitButtonId).toBe(submitButtonId);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user