/** * 506-3 다 — CAD 되돌리기 두 흠. * 6-f 특성 판 색 끌기 = 끄는 동안 화면만 · 멎은 뒤 되돌리기 한 칸(리본 색 칸과 같은 `paintNowCommitLater`). * 6-g LAYMRG = 사본으로 갈아 끼움 → Ctrl+Z 한 번에 옛 층. * 실행: cd B07_DesignDetail/openwebcad && npx vitest run --config vitest.tmp.config.ts undo-506-3 */ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; vi.mock("react-toastify", () => ({ toast: Object.assign(vi.fn(), { error: vi.fn(), info: vi.fn(), warn: vi.fn(), success: vi.fn() }), })); import { paintNowCommitLater, styleTargets, } from "../../../B07_DesignDetail/openwebcad/src/helpers/selection-style"; import { getSelectedEntities, resetUndoBaseline, setActiveLayerId, setLayers, setSelectedEntityIds, undo, } from "../../../B07_DesignDetail/openwebcad/src/state"; import { click, entities, initIdle, key, type } from "./helpers/cad-drive"; const layer = (id: string) => ({ id, name: id, isVisible: true, isLocked: false }); const line = (a: string, b: string) => { type("l"); type(a); type(b); key("Escape"); }; beforeEach(() => { initIdle(); setLayers([layer("A"), layer("B")]); setActiveLayerId("A"); }); afterEach(() => vi.useRealTimers()); describe("6-f 특성 판 색 끌기", () => { it("끄는 동안 다섯 번 = 되돌리기 한 칸 · Ctrl+Z 한 번에 옛 색", () => { line("0,0", "20,0"); const before = entities()[0].lineColor; resetUndoBaseline(); setSelectedEntityIds([entities()[0].id]); vi.useFakeTimers(); for (const color of ["#110000", "#220000", "#330000", "#440000", "#550000"]) { paintNowCommitLater(styleTargets(getSelectedEntities()), (entity) => { entity.lineColor = color; }); vi.advanceTimersByTime(50); // 끄는 중(멎기 전) } expect(entities()[0].lineColor).toBe("#550000"); vi.advanceTimersByTime(400); // 멎음 → 한 칸 undo(); expect(entities()[0].lineColor).toBe(before); }); }); describe("6-g LAYMRG", () => { it("병합 뒤 Ctrl+Z 한 번 = 옛 층", () => { line("0,0", "20,0"); setActiveLayerId("B"); line("0,50", "20,50"); resetUndoBaseline(); const [onA, onB] = entities(); expect([onA.layerId, onB.layerId]).toEqual(["A", "B"]); type("laymrg"); click(10, 0); click(10, 50); expect(entities().map((entity) => entity.layerId)).toEqual(["B", "B"]); undo(); expect(entities().map((entity) => entity.layerId)).toEqual(["A", "B"]); }); });