136 lines
3.9 KiB
TypeScript
136 lines
3.9 KiB
TypeScript
import { describe, expect, it } from '@jest/globals'
|
|
import {
|
|
resolveSelectionAfterPointAction,
|
|
resolveVisibilityMenuLabel,
|
|
resolveCopyMaterialSourcePanelId,
|
|
resolveMaterialTargetPanelIds,
|
|
} from '@/lib/assembly-context-menu-rules'
|
|
|
|
describe('assembly-context-menu-rules', () => {
|
|
describe('resolveSelectionAfterPointAction', () => {
|
|
it('Ctrl 追加选择时应把命中部件并入现有选集', () => {
|
|
const next = resolveSelectionAfterPointAction({
|
|
currentSelectionIds: ['A', 'B', 'C'],
|
|
hitPanelId: 'D',
|
|
appendSelection: true,
|
|
preserveSelectionOnBlank: true,
|
|
})
|
|
|
|
expect(next).toEqual(['A', 'B', 'C', 'D'])
|
|
})
|
|
|
|
it('Ctrl 追加选择命中已选部件时应保持不重复', () => {
|
|
const next = resolveSelectionAfterPointAction({
|
|
currentSelectionIds: ['A', 'B'],
|
|
hitPanelId: 'B',
|
|
appendSelection: true,
|
|
preserveSelectionOnBlank: true,
|
|
})
|
|
|
|
expect(next).toEqual(['A', 'B'])
|
|
})
|
|
|
|
it('空白右键且配置为保留选集时应保持当前选集', () => {
|
|
const next = resolveSelectionAfterPointAction({
|
|
currentSelectionIds: ['A', 'B'],
|
|
hitPanelId: null,
|
|
appendSelection: false,
|
|
preserveSelectionOnBlank: true,
|
|
})
|
|
|
|
expect(next).toEqual(['A', 'B'])
|
|
})
|
|
|
|
it('空白右键且不保留选集时应清空选集', () => {
|
|
const next = resolveSelectionAfterPointAction({
|
|
currentSelectionIds: ['A', 'B'],
|
|
hitPanelId: null,
|
|
appendSelection: false,
|
|
preserveSelectionOnBlank: false,
|
|
})
|
|
|
|
expect(next).toEqual([])
|
|
})
|
|
|
|
it('普通点击命中部件时应切换为单选该部件', () => {
|
|
const next = resolveSelectionAfterPointAction({
|
|
currentSelectionIds: ['A', 'B'],
|
|
hitPanelId: 'D',
|
|
appendSelection: false,
|
|
preserveSelectionOnBlank: true,
|
|
})
|
|
|
|
expect(next).toEqual(['D'])
|
|
})
|
|
|
|
it('防回归:先追加后普通点击时应回到单选,不受安装顺序逻辑影响', () => {
|
|
const appended = resolveSelectionAfterPointAction({
|
|
currentSelectionIds: ['A'],
|
|
hitPanelId: 'B',
|
|
appendSelection: true,
|
|
preserveSelectionOnBlank: true,
|
|
})
|
|
|
|
const singleSelected = resolveSelectionAfterPointAction({
|
|
currentSelectionIds: appended,
|
|
hitPanelId: 'C',
|
|
appendSelection: false,
|
|
preserveSelectionOnBlank: true,
|
|
})
|
|
|
|
expect(appended).toEqual(['A', 'B'])
|
|
expect(singleSelected).toEqual(['C'])
|
|
})
|
|
})
|
|
|
|
describe('resolveVisibilityMenuLabel', () => {
|
|
it('有选集时应显示隐藏所选部件', () => {
|
|
expect(resolveVisibilityMenuLabel(2)).toBe('隐藏已选板件')
|
|
})
|
|
|
|
it('无选集时应显示显示全部部件', () => {
|
|
expect(resolveVisibilityMenuLabel(0)).toBe('显示全部板件')
|
|
})
|
|
})
|
|
|
|
describe('resolveCopyMaterialSourcePanelId', () => {
|
|
it('多选时应优先使用右键命中部件作为复制来源', () => {
|
|
const source = resolveCopyMaterialSourcePanelId({
|
|
hitPanelId: 'C',
|
|
selectedPanelIds: ['A', 'B', 'C'],
|
|
})
|
|
|
|
expect(source).toBe('C')
|
|
})
|
|
|
|
it('无命中部件时应回退到选集第一个部件', () => {
|
|
const source = resolveCopyMaterialSourcePanelId({
|
|
hitPanelId: null,
|
|
selectedPanelIds: ['A', 'B', 'C'],
|
|
})
|
|
|
|
expect(source).toBe('A')
|
|
})
|
|
})
|
|
|
|
describe('resolveMaterialTargetPanelIds', () => {
|
|
it('多选时快速材质/粘贴材质应应用到全部选集', () => {
|
|
const targets = resolveMaterialTargetPanelIds({
|
|
selectedPanelIds: ['A', 'B', 'C'],
|
|
fallbackPanelId: 'D',
|
|
})
|
|
|
|
expect(targets).toEqual(['A', 'B', 'C'])
|
|
})
|
|
|
|
it('无选集时应回退到命中部件', () => {
|
|
const targets = resolveMaterialTargetPanelIds({
|
|
selectedPanelIds: [],
|
|
fallbackPanelId: 'D',
|
|
})
|
|
|
|
expect(targets).toEqual(['D'])
|
|
})
|
|
})
|
|
})
|