/** * 옮기기 · 크기 · 회전 · 복사 · 배열 복제가 색 · 층 · 선 꼴을 지키는지(84-3). * 실행: cd B07_DesignDetail/openwebcad && npx vitest run --config */ import { Point } from "@flatten-js/core"; import { describe, expect, it } from "vitest"; import { LineEntity } from "../../../B07_DesignDetail/openwebcad/src/entities/LineEntity"; import { PointEntity } from "../../../B07_DesignDetail/openwebcad/src/entities/PointEntity"; import { PolyLineEntity } from "../../../B07_DesignDetail/openwebcad/src/entities/PolyLineEntity"; import { TextEntity } from "../../../B07_DesignDetail/openwebcad/src/entities/TextEntity"; import { cloneKeepingLook } from "../../../B07_DesignDetail/openwebcad/src/tools/move-tool.helpers"; import type { Entity } from "../../../B07_DesignDetail/openwebcad/src/entities/Entity"; const styled = (entity: T): T => { entity.lineColor = "#ff0000"; entity.lineWidth = 2; entity.lineDash = [4, 2]; entity.opacity = 0.5; entity.groupId = "g1"; return entity; }; const look = (entity: Entity) => [ entity.layerId, entity.lineColor, entity.lineWidth, entity.lineDash, entity.opacity, ]; const LOOK = ["구조물", "#ff0000", 2, [4, 2], 0.5]; describe("cloneKeepingLook", () => { const samples: [string, () => Entity][] = [ ["선", () => styled(new LineEntity("구조물", new Point(0, 0), new Point(1, 0)))], ["점", () => styled(new PointEntity("구조물", new Point(1, 1)))], ["글", () => styled(new TextEntity("구조물", "배수관", new Point(0, 0)))], ]; for (const [name, make] of samples) { it(`${name} — 옮기기(inPlace) 는 id · 묶음 · 색 · 층 그대로`, () => { const source = make(); const copy = cloneKeepingLook(source, true); copy.move(5, 5); expect(look(copy)).toEqual(LOOK); expect([copy.id, copy.groupId]).toEqual([source.id, "g1"]); }); it(`${name} — 복사는 새 id · 색 · 층 그대로`, () => { const source = make(); const copy = cloneKeepingLook(source); expect(look(copy)).toEqual(LOOK); expect(copy.id).not.toBe(source.id); }); } it("폴리선 — 자식 선까지 색 · 층 그대로(크기 바꿈 뒤)", () => { const child = styled(new LineEntity("구조물", new Point(0, 0), new Point(1, 0))); const polyline = styled(new PolyLineEntity("구조물", [child])); const copy = cloneKeepingLook(polyline, true) as PolyLineEntity; copy.scale(new Point(0, 0), 2); expect(look(copy)).toEqual(LOOK); expect(look(copy.getEntities()[0])).toEqual(LOOK); }); });