- 대상 교각을 원본 아래(2번)로 올리고, 기본 0기로 시작
- 같은 형식 모두 선택 / 선택 해제 버튼 추가, 모델 없는 교각은 고를 수 없음
- 적용 버튼에 대상 이름을 표시 ("P1, P5 2기에만 적용"), 미리보기는 고른 교각만 표시
- 후보·선택 규칙을 core/copy-targets.ts로 분리하고 테스트 6건 추가
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { copyCandidates, selectedTargets, type CopyCandidate } from '../src/core/copy-targets';
|
|
|
|
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', false).map((c) => c.name)).not.toContain('P3');
|
|
});
|
|
|
|
it('keeps only the source type when 같은 형식만 is on', () => {
|
|
expect(copyCandidates(piers, 'P3', true).map((c) => c.name)).toEqual(['P1', 'P2', 'P5']);
|
|
});
|
|
|
|
it('marks a pier without a model as not selectable', () => {
|
|
const p5 = copyCandidates(piers, 'P3', false).find((c) => c.name === 'P5');
|
|
expect(p5?.selectable).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('selectedTargets (선택한 대상만)', () => {
|
|
it('is empty when nothing is ticked', () => {
|
|
expect(selectedTargets(piers, 'P3', false, new Set())).toEqual([]);
|
|
});
|
|
|
|
it('returns only ticked, selectable piers', () => {
|
|
const picked = new Set(['P1', 'P4', 'P5']);
|
|
expect(selectedTargets(piers, 'P3', false, picked)).toEqual(['P1', 'P4']);
|
|
});
|
|
|
|
it('ignores a tick on a pier hidden by the same-type filter', () => {
|
|
const picked = new Set(['P4']);
|
|
expect(selectedTargets(piers, 'P3', true, picked)).toEqual([]);
|
|
});
|
|
});
|