import { describe, expect, it } from 'vitest'; import { applyOverrides, overrideTargets, shownNames, type PierSelection } from '../src/core/active-piers'; import { loadP1 } from './helpers'; const list: PierSelection[] = [ { name: 'P1', checked: true, hasModel: true }, { name: 'P2', checked: true, hasModel: true }, { name: 'P3', checked: false, hasModel: true }, { name: 'P4', checked: true, hasModel: false }, ]; describe('shownNames (체크 = 활성, 기준 교각은 항상 표시)', () => { it('shows every checked pier that has a model, in list order', () => { expect(shownNames(list, 'P1')).toEqual(['P1', 'P2']); }); it('keeps the 기준 pier even when it is unchecked', () => { expect(shownNames(list, 'P3')).toEqual(['P1', 'P2', 'P3']); }); it('never shows a pier without a model', () => { expect(shownNames(list, 'P4')).toEqual(['P1', 'P2']); }); it('shows only the 기준 pier when nothing else is checked', () => { const none = list.map((p) => ({ ...p, checked: false })); expect(shownNames(none, 'P2')).toEqual(['P2']); }); }); describe('overrideTargets (기준 교각의 수정 값을 받을 교각)', () => { it('is the checked piers other than the 기준 pier', () => { expect(overrideTargets(list, 'P1')).toEqual(['P2']); expect(overrideTargets(list, 'P3')).toEqual(['P1', 'P2']); }); }); describe('applyOverrides (기준 교각의 변경 항목만 옮김)', () => { const base = loadP1(); const defaults = base; const edited = { ...base, copingWidthMm: base.copingWidthMm + 100 }; const target = { ...base, copingLengthMm: base.copingLengthMm + 500 }; it('copies only the keys the 기준 pier overrides, keeping the target own values', () => { const next = applyOverrides({ defaults, input: defaults, draft: edited }, target); expect(next.copingWidthMm).toBe(edited.copingWidthMm); expect(next.copingLengthMm).toBe(target.copingLengthMm); }); it('returns the target unchanged when the 기준 pier has no overrides', () => { const next = applyOverrides({ defaults, input: defaults, draft: defaults }, target); expect(next).toEqual(target); }); });