- 1-A 도면 GET · 저장 PUT 한도 60 s · 저장 중 미리받기 쉼 · 끊긴 저장 = 목록 confirmed 로 판정
- 2 CAD 자동백업 열쇠 = b07:{프로젝트}:{도면} · 도각 편집 = b07-frame:{프로젝트} · [초기화] 같은 열쇠
- 3-1 [초기화] 물음 글 = 프로젝트 도각 그대로 · [도각 편집] → [기본 도각 복원] 안내
- 3-2 풀린 장 저장본 json · 수량표 찌꺼기 걷음(_write_manifest 한 곳)
- 5-1 확정 풀기 · 배치 · 축척 = mark_stage(save)
- 7-3 start_stage 가 DEV_UNLOCK 표식 남김
- 6-a navigateDrawing · onNavigate · hasPrev · hasNext 걷음 · 6-b cad-host-save 토글 걷음 · 4-2 B08 안 쓰는 글 11 걷음
- 6-f 특성 판 색 끌기 = 되돌리기 한 칸(paintNowCommitLater 한 벌) · 6-g LAYMRG 사본 길
- 4-1 B09 [인쇄 미리보기] = 저장 뒤 이동 · 단계 그대로 · 6-e M02 카드 도움말 DWG 한 줄
- 시험 test_506_3_* 둘 · cad/undo-506-3 · test_298_2_b07_buttons 열쇠 맞춤
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
143 lines
4.2 KiB
TypeScript
143 lines
4.2 KiB
TypeScript
import { beforeAll, describe, expect, it } from 'vitest';
|
|
import type { DesignMeta } from './App.types';
|
|
import type { Entity } from './entities/Entity';
|
|
import {
|
|
clearDrawingDirty,
|
|
getActiveLayerId,
|
|
getEntities,
|
|
getHighlightedEntityIds,
|
|
isDrawingDirty,
|
|
isBare,
|
|
isDrawingReadOnly,
|
|
resetUndoBaseline,
|
|
setActiveLayerId,
|
|
setBare,
|
|
setDesignMeta,
|
|
setEntities,
|
|
setHighlightedEntityIds,
|
|
setLayers,
|
|
undo,
|
|
} from './state';
|
|
|
|
const layer = (id: string, isLocked: boolean) => ({
|
|
id,
|
|
name: id,
|
|
isVisible: true,
|
|
isLocked,
|
|
});
|
|
|
|
/** 노드 환경에는 window가 없다 — 상태 알림을 받는 시늉만 시킨다. */
|
|
const stubWindow = () => {
|
|
(globalThis as { window?: unknown }).window = { dispatchEvent: () => true };
|
|
};
|
|
|
|
const entityOnLayer = (id: string, layerId: string) => ({ id, layerId }) as unknown as Entity;
|
|
|
|
const meta = (confirmed: boolean): DesignMeta => ({
|
|
kind: 'cross',
|
|
drawingId: 'cross_s00020m',
|
|
title: '1장',
|
|
info: '',
|
|
confirmed,
|
|
quantityTable: null,
|
|
});
|
|
|
|
describe('setActiveLayerId', () => {
|
|
it('잠금 도면층(배경)은 현재 도면층이 되지 않고 잠금 아닌 첫 층으로 간다', () => {
|
|
setLayers([layer('도각', true), layer('계획선', false)]);
|
|
setActiveLayerId('도각');
|
|
expect(getActiveLayerId()).toBe('계획선');
|
|
});
|
|
|
|
it('잠금 아닌 층이 하나도 없으면 요청값을 그대로 둔다', () => {
|
|
setLayers([layer('도각', true)]);
|
|
setActiveLayerId('도각');
|
|
expect(getActiveLayerId()).toBe('도각');
|
|
});
|
|
});
|
|
|
|
describe('resetUndoBaseline', () => {
|
|
beforeAll(stubWindow);
|
|
|
|
it('기준선을 세운 뒤의 되돌리기는 실은 도면까지만 물러난다', () => {
|
|
const loaded = [{ id: 'a' } as unknown as Entity];
|
|
setEntities(loaded, false);
|
|
resetUndoBaseline();
|
|
setEntities([...loaded, { id: 'b' } as unknown as Entity], true);
|
|
undo();
|
|
expect(getEntities()).toHaveLength(1);
|
|
});
|
|
});
|
|
|
|
describe('setHighlightedEntityIds', () => {
|
|
it('잠금 도면층(도각·등고선) 객체는 마우스가 가도 밝아지지 않는다', () => {
|
|
setLayers([layer('도각', true), layer('계획선', false)]);
|
|
setEntities([entityOnLayer('배경', '도각'), entityOnLayer('내선', '계획선')], false);
|
|
setHighlightedEntityIds(['배경', '내선']);
|
|
expect(getHighlightedEntityIds()).toEqual(['내선']);
|
|
});
|
|
|
|
it('잠금층만 가리키면 아무것도 밝아지지 않는다', () => {
|
|
setLayers([layer('도각', true)]);
|
|
setEntities([entityOnLayer('배경', '도각')], false);
|
|
setHighlightedEntityIds(['배경']);
|
|
expect(getHighlightedEntityIds()).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('미저장 표시(drawingDirty)', () => {
|
|
beforeAll(stubWindow);
|
|
|
|
it('편집하면 서고, 도면을 새로 실으면(기준선 재설정) 내려간다', () => {
|
|
setEntities([entityOnLayer('a', 'L')], false);
|
|
resetUndoBaseline();
|
|
expect(isDrawingDirty()).toBe(false);
|
|
setEntities([entityOnLayer('a', 'L'), entityOnLayer('b', 'L')], true);
|
|
expect(isDrawingDirty()).toBe(true);
|
|
resetUndoBaseline();
|
|
expect(isDrawingDirty()).toBe(false);
|
|
});
|
|
|
|
it('되돌리기도 미저장이다 — 저장본과 달라질 수 있다', () => {
|
|
setEntities([entityOnLayer('a', 'L')], false);
|
|
resetUndoBaseline();
|
|
setEntities([entityOnLayer('a', 'L'), entityOnLayer('b', 'L')], true);
|
|
clearDrawingDirty();
|
|
undo();
|
|
expect(isDrawingDirty()).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('isDrawingReadOnly', () => {
|
|
beforeAll(stubWindow);
|
|
|
|
it('확정한 도면은 읽기 전용, 확정을 풀면 편집이 열린다', () => {
|
|
setDesignMeta(meta(true));
|
|
expect(isDrawingReadOnly()).toBe(true);
|
|
setDesignMeta(meta(false));
|
|
expect(isDrawingReadOnly()).toBe(false);
|
|
setDesignMeta(null);
|
|
expect(isDrawingReadOnly()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('setBare', () => {
|
|
it('캔버스만 — 켜면 뿌리에 cad-bare(제목줄 · 상태막대 0), 끄면 걷힌다', () => {
|
|
stubWindow();
|
|
const classes = new Set<string>();
|
|
(globalThis as { document?: unknown }).document = {
|
|
documentElement: {
|
|
classList: {
|
|
toggle: (name: string, on: boolean) => (on ? classes.add(name) : classes.delete(name)),
|
|
},
|
|
},
|
|
};
|
|
setBare(true);
|
|
expect(isBare()).toBe(true);
|
|
expect(classes.has('cad-bare')).toBe(true);
|
|
setBare(false);
|
|
expect(isBare()).toBe(false);
|
|
expect(classes.has('cad-bare')).toBe(false);
|
|
});
|
|
});
|