104 lines
4.2 KiB
TypeScript
104 lines
4.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { copyCandidates, copyItemsFor, copyItemsWithOverrides, hasCopyItems, selectedTargets, type CopyCandidate } from '../src/core/copy-targets';
|
|
import { loadP1 } from './helpers';
|
|
|
|
const piers: CopyCandidate[] = [
|
|
{ name: 'P1', type: 'T형', hasModel: true },
|
|
{ name: 'P2', type: 'T형', hasModel: true },
|
|
{ name: 'P3', type: 'T형', hasModel: true },
|
|
{ name: 'P4', type: 'Y형', hasModel: true },
|
|
{ name: 'P5', type: 'T형', hasModel: false },
|
|
];
|
|
|
|
describe('copyCandidates (대상 후보)', () => {
|
|
it('excludes the source pier', () => {
|
|
expect(copyCandidates(piers, 'P3').map((c) => c.name)).not.toContain('P3');
|
|
});
|
|
|
|
it('offers piers of every type, so a different type is visible', () => {
|
|
expect(copyCandidates(piers, 'P3').map((c) => c.type)).toEqual(['T형', 'T형', 'Y형', 'T형']);
|
|
});
|
|
|
|
it('marks a pier without a model as not selectable', () => {
|
|
const p5 = copyCandidates(piers, 'P3').find((c) => c.name === 'P5');
|
|
expect(p5?.selectable).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('selectedTargets (선택한 대상만)', () => {
|
|
it('is empty when nothing is ticked', () => {
|
|
expect(selectedTargets(piers, 'P3', new Set())).toEqual([]);
|
|
});
|
|
|
|
it('returns only ticked, selectable piers', () => {
|
|
const picked = new Set(['P1', 'P4', 'P5']);
|
|
expect(selectedTargets(piers, 'P3', picked)).toEqual(['P1', 'P4']);
|
|
});
|
|
|
|
it('keeps a tick on a pier of another type', () => {
|
|
expect(selectedTargets(piers, 'P3', new Set(['P4']))).toEqual(['P4']);
|
|
});
|
|
});
|
|
|
|
describe('copyItemsFor (부재 선택에 해당하는 복사 항목)', () => {
|
|
it('coping copies only the coping items', () => {
|
|
expect(copyItemsFor('coping')).toEqual(['coping-width', 'coping-length', 'coping-h1', 'coping-h2', 'level-width']);
|
|
});
|
|
|
|
it('확대기초 · 말뚝 copies only the pile items', () => {
|
|
expect(copyItemsFor('footing')).toEqual(['pile-length', 'pile-rows']);
|
|
});
|
|
|
|
it('지반 copies only the ground position', () => {
|
|
expect(copyItemsFor('ground')).toEqual(['ground-position']);
|
|
});
|
|
|
|
it('기둥 and 받침 have no copy items yet', () => {
|
|
expect(copyItemsFor('column')).toEqual([]);
|
|
expect(copyItemsFor('bearing')).toEqual([]);
|
|
});
|
|
|
|
it('every copy item belongs to exactly one member', () => {
|
|
const all = (['bearing', 'coping', 'column', 'footing', 'ground'] as const).flatMap((m) => copyItemsFor(m));
|
|
expect([...all].sort()).toEqual(['coping-h1', 'coping-h2', 'coping-length', 'coping-width', 'ground-position', 'level-width', 'pile-length', 'pile-rows']);
|
|
});
|
|
});
|
|
|
|
describe('copyItemsWithOverrides (기준 교각에서 되돌리기가 표시된 항목)', () => {
|
|
const base = loadP1();
|
|
const source = (draft: Partial<typeof base>) => ({ defaults: base, input: base, draft: { ...base, ...draft } });
|
|
|
|
it('is empty when the 기준 pier has no changed values', () => {
|
|
expect(copyItemsWithOverrides(source({}))).toEqual([]);
|
|
});
|
|
|
|
it('selects the item of a changed coping length', () => {
|
|
expect(copyItemsWithOverrides(source({ copingLengthMm: base.copingLengthMm + 500 }))).toEqual(['coping-length']);
|
|
});
|
|
|
|
it('selects the pile item when the pile length changed', () => {
|
|
expect(copyItemsWithOverrides(source({ pileLengthMm: base.pileLengthMm + 100 }))).toEqual(['pile-length']);
|
|
});
|
|
|
|
it('selects the coping h1, h2 and Level 폭 items when those values changed', () => {
|
|
expect(copyItemsWithOverrides(source({ copingH1Mm: (base.copingH1Mm ?? 0) + 1, levelWidthMm: (base.levelWidthMm ?? 0) + 1 }))).toEqual(['coping-h1', 'level-width']);
|
|
});
|
|
|
|
it('ignores a changed value that no copy item carries (groundEl)', () => {
|
|
expect(copyItemsWithOverrides(source({ groundEl: base.groundEl + 0.5 }))).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('hasCopyItems (속성 복사 패널을 보일지)', () => {
|
|
it('shows the panel for coping, 확대기초·말뚝 and 지반', () => {
|
|
expect(hasCopyItems('coping')).toBe(true);
|
|
expect(hasCopyItems('footing')).toBe(true);
|
|
expect(hasCopyItems('ground')).toBe(true);
|
|
});
|
|
|
|
it('hides the panel for 교량받침 and 기둥 (no copy items yet)', () => {
|
|
expect(hasCopyItems('bearing')).toBe(false);
|
|
expect(hasCopyItems('column')).toBe(false);
|
|
});
|
|
});
|