Files
Aislo/B07_DesignDetail/openwebcad/src/integration/guide-area.test.ts
T

83 lines
3.1 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import {
GUIDE_MIN_MM,
type GuideArea,
dragGuideArea,
drawGuide,
getGuide,
isGuideVisible,
pickGuideHandle,
setGuide,
setGuideArea,
setGuideVisible,
} from './guide-area.ts';
import type { ScreenCanvasDrawController } from '../drawControllers/screenCanvas.drawController.ts';
const AREA: GuideArea = [42, 47, 812, 567];
describe('작도 영역 가이드(169-1 · 169-3)', () => {
it('싣기 — 어긋난 영역은 가이드 없음 · 갈기는 가이드가 있을 때만', () => {
setGuide({ area: [10, 10, 5, 20] });
expect(getGuide()).toBeNull();
setGuideArea(AREA);
expect(getGuide()).toBeNull();
setGuide({ area: AREA, marks: [[0, 0, 1, 1], 'x'], editable: true });
expect(getGuide()).toEqual({ area: AREA, marks: [[0, 0, 1, 1]], editable: true });
setGuideArea([0, 0, 100, 50]);
expect(getGuide()?.area).toEqual([0, 0, 100, 50]);
setGuide(null);
expect(getGuide()).toBeNull();
});
it('손잡이 — 모서리가 변보다 먼저 · 허용 거리 밖은 없음', () => {
expect(pickGuideHandle(AREA, { x: 812, y: 567 }, 2)).toBe('ne');
expect(pickGuideHandle(AREA, { x: 43, y: 46 }, 2)).toBe('sw');
expect(pickGuideHandle(AREA, { x: 400, y: 566 }, 2)).toBe('n');
expect(pickGuideHandle(AREA, { x: 811, y: 300 }, 2)).toBe('e');
expect(pickGuideHandle(AREA, { x: 400, y: 300 }, 2)).toBeNull();
expect(pickGuideHandle(AREA, { x: 900, y: 567 }, 2)).toBeNull();
});
it('끌기 — 반대편 그대로 · 0.1 mm 반올림 · 최소 크기', () => {
expect(dragGuideArea(AREA, 'ne', { x: 800.04, y: 560.06 })).toEqual([42, 47, 800, 560.1]);
expect(dragGuideArea(AREA, 'w', { x: 50, y: 0 })).toEqual([50, 47, 812, 567]);
expect(dragGuideArea(AREA, 's', { x: 0, y: 9999 })).toEqual([42, 567 - GUIDE_MIN_MM, 812, 567]);
expect(dragGuideArea(AREA, 'e', { x: -100, y: 0 })).toEqual([42, 47, 42 + GUIDE_MIN_MM, 567]);
});
it('안내선 보이기 / 숨기기(180-3) — 숨김이면 점선 영역 · 붉은 틀 안 그림 · 싣기를 거쳐도 이어짐', () => {
const lines = vi.fn();
const controller = {
setOpacity: vi.fn(),
setLineStyles: vi.fn(),
worldToTarget: (point: unknown) => point,
drawLineScreen: lines,
fillRectScreen: vi.fn(),
} as unknown as ScreenCanvasDrawController;
const guide = { area: AREA, marks: [[0, 0, 5, 5] as GuideArea], editable: false };
setGuide(guide);
expect(isGuideVisible()).toBe(true); // 기본 = 보임
drawGuide(controller);
expect(lines).toHaveBeenCalledTimes(8); // 점선 영역 4 변 + 붉은 틀 4 변
setGuideVisible(false);
lines.mockClear();
drawGuide(controller);
expect(lines).not.toHaveBeenCalled();
setGuide(guide); // 장을 다시 실어도 숨김 유지
setGuideArea([0, 0, 100, 50]);
drawGuide(controller);
expect(isGuideVisible()).toBe(false);
expect(lines).not.toHaveBeenCalled();
expect(getGuide()?.marks).toHaveLength(1); // 값은 그대로 — 그리기만 거름
setGuideVisible(true);
drawGuide(controller);
expect(lines).toHaveBeenCalledTimes(8);
setGuideVisible('x'); // 어긋난 값 = 보임
expect(isGuideVisible()).toBe(true);
setGuide(null);
});
});