Files
Aislo/resources/tester/cad/block-library.test.ts
T
eomsangdonandClaude Opus 5 0ef32b5279 chore(tester): 시험을 resources/tester/ 로 옮김 — 창끼리 건너가게
⚠ **뿌리** — `tmp/` 는 창 사이에 안 건너감(실측 확인: 상대 창이 놓은 `tmp/_sync_probe.txt`
가 시간을 두고 두 번 봐도 안 보임). 그래서 **정본(등록부 스키마)만 건너가고 그것을 읽는
시험은 안 건너가** 오늘 두 번, 같은 시험이 **연 창은 통과·받은 창은 실패**가 됐음.

- `tmp/tests/*` 를 `resources/tester/` 로 **복사**(127 파일). 내용은 **한 줄도 안 고침**
- `tmp/tests` 는 **남겨 둠** — 되돌릴 자리(사용자 지시)
- 실행: `./venv/Scripts/python.exe -m pytest resources/tester/ -q`
  옮기기 전과 **같은 수**: 617 통과 / 22 건너뜀 / 실패 0

⇒ 이제 시험·예외·까닭이 **정본과 함께** 움직임. 오늘 세운 「예외는 정본 스키마에」와 짝임.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-09 17:12:30 +09:00

51 lines
2.0 KiB
TypeScript

/**
* 블록 라이브러리 저장·해제 검증 (조사표 4절 BLOCK/INSERT).
* 실행: cd B07_DesignDetail/openwebcad && npx vitest run --config vitest.tmp.config.ts
* jsdom을 새로 깔지 않으려고 이 모듈이 쓰는 브라우저 전역 둘만 흉내 낸다.
*/
import { Point, Segment } from '@flatten-js/core';
import { describe, expect, it } from 'vitest';
const store = new Map<string, string>();
Object.assign(globalThis, {
window: { dispatchEvent: () => true },
CustomEvent: class {
constructor(public type: string) {}
},
localStorage: {
getItem: (key: string) => store.get(key) ?? null,
setItem: (key: string, value: string) => void store.set(key, value),
},
});
const { deleteBlock, deserializeBlock, getBlocks, saveBlockFromEntities } = await import(
'../../../B07_DesignDetail/openwebcad/src/blocks/block-library'
);
const { LineEntity } = await import(
'../../../B07_DesignDetail/openwebcad/src/entities/LineEntity'
);
describe('블록 라이브러리', () => {
it('기준점은 선택 영역 중심이고, 다시 풀어 삽입점으로 옮기면 그 점이 중심이 된다', async () => {
const line = new LineEntity('layer-1', new Segment(new Point(0, 0), new Point(100, 50)));
await saveBlockFromEntities('테스트블록', [line]);
const block = getBlocks().find((candidate) => candidate.name === '테스트블록');
expect(block).toBeDefined();
if (!block) return;
expect(block.basePoint).toEqual({ x: 50, y: 25 });
const [copy] = await deserializeBlock(block);
expect(copy.id).not.toBe(line.id);
expect(copy.groupId).toBeTruthy();
// 삽입점 (200, 100)으로 옮기면 원본 크기 100×50이 그 점을 중심으로 놓인다
copy.move(200 - block.basePoint.x, 100 - block.basePoint.y);
const box = copy.getBoundingBox();
expect([box.xmin, box.ymin, box.xmax, box.ymax]).toEqual([150, 75, 250, 125]);
deleteBlock('테스트블록');
expect(getBlocks().find((candidate) => candidate.name === '테스트블록')).toBeUndefined();
});
});