furniture-3d-system-Wu/tests/lib/cad-panel-linking.test.ts

56 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from '@jest/globals'
import {
collectRequiredPanelIds,
getPanelNodeAliases,
inferFallbackPanelSizeFromHoles,
normalizePanelNodeName,
} from '@/lib/cad-panel-linking'
describe('cad-panel-linking', () => {
it('应该规范化 panel 节点名称并生成别名', () => {
const normalized = normalizePanelNodeName(' Cabinet\\Body/Panel_01 ')
const aliases = getPanelNodeAliases(' Cabinet\\Body/Panel_01 ')
expect(normalized).toBe('cabinet/body/panel_01')
expect(aliases).toContain('cabinet/body/panel_01')
expect(aliases).toContain('panel_01')
})
it('应该在没有孔位时返回默认板件尺寸', () => {
const size = inferFallbackPanelSizeFromHoles([], 'panel_001')
expect(size).toEqual([600, 400, 18])
})
it('应该根据孔位分布推断出有效板件尺寸', () => {
const size = inferFallbackPanelSizeFromHoles(
[
{ panelId: 'panel_001', position: [100, 200, 0], normal: [0, 0, 1] },
{ panelId: 'panel_001', position: [360, 260, 0], normal: [0, 0, 1] },
{ panelId: 'panel_001', position: [160, 420, 0], normal: [0, 0, 1] },
],
'panel_001'
)
expect(size[0]).toBeGreaterThanOrEqual(size[1])
expect(size[1]).toBeGreaterThanOrEqual(size[2])
expect(size[2]).toBeGreaterThan(0)
})
it('应合并 CAD 板件和孔位里的 panelId,包含无孔位板件', () => {
const panelIds = collectRequiredPanelIds(
[
{ id: 'panel_000' },
{ id: ' panel_001 ' },
{ id: '' },
],
[
{ panelId: 'panel_001' },
{ panelId: 'panel_002' },
]
)
expect(panelIds).toEqual(['panel_000', 'panel_001', 'panel_002'])
})
})