76 lines
2.7 KiB
TypeScript
76 lines
2.7 KiB
TypeScript
import { describe, expect, it } from '@jest/globals'
|
|
import type { MaterialCategoryWithMaterials, MaterialConfig } from '@/lib/3d/material-manager'
|
|
import { buildAssemblyQuickMaterialCategories } from '@/lib/assembly-quick-material-categories'
|
|
|
|
function createMaterial(id: string, name: string, categoryName?: string): MaterialConfig {
|
|
return {
|
|
id,
|
|
name,
|
|
categoryId: `cat-${id}`,
|
|
categoryName,
|
|
thumbnailUrl: '/materials/thumbnails/default.svg',
|
|
color: '#FFFFFF',
|
|
metalness: 0.1,
|
|
roughness: 0.6,
|
|
opacity: 1,
|
|
}
|
|
}
|
|
|
|
function createCategory(
|
|
id: string,
|
|
name: string,
|
|
materials: MaterialConfig[],
|
|
sortOrder = 0
|
|
): MaterialCategoryWithMaterials {
|
|
return {
|
|
id,
|
|
name,
|
|
icon: null,
|
|
sortOrder,
|
|
materials,
|
|
}
|
|
}
|
|
|
|
describe('assembly-quick-material-categories', () => {
|
|
it('将玻璃和亚克力合并到“透明”,并隐藏“石材”分类名', () => {
|
|
const source = [
|
|
createCategory('glass', '玻璃', [createMaterial('m1', '超白玻璃', '玻璃')], 1),
|
|
createCategory('acrylic', '亚克力', [createMaterial('m2', '透明亚克力', '亚克力')], 2),
|
|
createCategory('stone', '石材', [createMaterial('m3', '岩板', '石材')], 3),
|
|
]
|
|
|
|
const result = buildAssemblyQuickMaterialCategories(source)
|
|
const transparent = result.find((category) => category.name === '透明')
|
|
|
|
expect(transparent).toBeTruthy()
|
|
expect(transparent?.materials.map((material) => material.id)).toEqual(['m1', 'm2'])
|
|
expect(result.some((category) => category.name === '石材')).toBe(false)
|
|
})
|
|
|
|
it('把未收敛分类归入“其他”,并始终保留“其他”分类', () => {
|
|
const source = [
|
|
createCategory('wood', '木纹', [createMaterial('m1', '橡木', '木纹')], 1),
|
|
createCategory('special', '岩板特供', [createMaterial('m2', '玄武岩', '岩板特供')], 2),
|
|
]
|
|
|
|
const result = buildAssemblyQuickMaterialCategories(source)
|
|
const otherCategory = result.find((category) => category.name === '其他')
|
|
|
|
expect(otherCategory).toBeTruthy()
|
|
expect(otherCategory?.materials.map((material) => material.id)).toEqual(['m2'])
|
|
})
|
|
|
|
it('即使没有未收敛材质,也保留“其他”分类用于后续扩展', () => {
|
|
const source = [
|
|
createCategory('wood', '木纹', [createMaterial('m1', '白橡木', '木纹')], 1),
|
|
createCategory('metal', '金属', [createMaterial('m2', '拉丝不锈钢', '金属')], 2),
|
|
]
|
|
|
|
const result = buildAssemblyQuickMaterialCategories(source)
|
|
const otherCategory = result.find((category) => category.name === '其他')
|
|
|
|
expect(otherCategory).toBeTruthy()
|
|
expect(otherCategory?.materials).toHaveLength(0)
|
|
})
|
|
})
|