Files
Aislo/resources/tester/cad/dxf-clip.test.ts
T

52 lines
2.3 KiB
TypeScript

/**
* 오토캐드 도형 붙이기 순수 부분(`integration/dxf-clip.ts`) 검증.
* 실행: node --experimental-strip-types resources/tester/cad/dxf-clip.test.ts
* (타입만 가져오는 모듈이라 vitest · jsdom 없이 바로 돎)
*/
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import {
isDxfText,
prepareClip,
} from '../../../B07_DesignDetail/openwebcad/src/integration/dxf-clip.ts';
const sample = readFileSync('resources/tester/fixtures/b07_webclip_sample.dxf', 'utf-8');
assert.equal(isDxfText(sample), true, '견본 DXF 알아봄');
assert.equal(isDxfText(sample.replace(/\n/g, '\r\n')), true, 'CRLF DXF 도 알아봄');
assert.equal(isDxfText('0\nSECTION\n'), true, '앞 공백 없는 DXF');
assert.equal(isDxfText('가나다'), false, '보통 글은 아님');
assert.equal(isDxfText('0\nSECTIONS'), false, 'SECTION 뒤 글자 붙은 것은 아님');
const existing = [{ id: 'L-old', name: '구조물', isVisible: true, isLocked: false }];
const line = (id: string, layer: string) => ({
id,
type: 'Line',
lineColor: '#fff',
lineWidth: 1,
layerId: layer,
shapeData: { startPoint: { x: 0, y: 0 }, endPoint: { x: 1, y: 0 } },
});
const serverEntities = [
line('same', '구조물'),
{
...line('same', '치수글'),
type: 'PolyLine',
shapeData: null,
children: [line('same', '치수글')],
},
];
// biome-ignore lint: 시험 — 서버 JSON 모양 그대로
const out = prepareClip(serverEntities as any, [{ name: '치수글', color: '#00ff00' }], existing);
assert.equal(out.entities[0].layerId, 'L-old', '같은 이름 층은 기존 층으로');
assert.equal(out.newLayers.length, 1, '없는 층만 새로');
assert.equal(out.newLayers[0].name, '치수글');
assert.equal(out.newLayers[0].color, '#00ff00', '새 층은 DXF 층 색');
assert.equal(out.entities[1].layerId, out.newLayers[0].id, '새 층에 잇기');
assert.equal(out.entities[1].children?.[0].layerId, out.newLayers[0].id, '폴리선 속 선도 같은 층');
const ids = [out.entities[0].id, out.entities[1].id, out.entities[1].children?.[0].id];
assert.equal(new Set(ids).size, 3, 'id 는 모두 새로(서로 안 겹침)');
assert.ok(!ids.includes('same'), '서버 id 를 그대로 안 씀');
assert.deepEqual(out.entities[0].shapeData, serverEntities[0].shapeData, '좌표는 원좌표 그대로');
console.log('dxf-clip 시험 통과');