2026-05-20 10:59:17 +02:00
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
|
import {
|
|
|
|
|
|
buildSkillCatalogTree,
|
2026-05-20 11:16:49 +02:00
|
|
|
|
catalogSkillsForSelection,
|
2026-05-20 10:59:17 +02:00
|
|
|
|
collectSkillLeavesFromTree,
|
2026-05-20 11:16:49 +02:00
|
|
|
|
countCatalogSkillsWithoutCategory,
|
|
|
|
|
|
countCatalogSkillsWithoutMain,
|
2026-05-20 11:13:34 +02:00
|
|
|
|
defaultExpandedKeysForSkillTree,
|
2026-05-20 10:59:17 +02:00
|
|
|
|
filterSkillTreeByQuery,
|
2026-05-20 11:16:49 +02:00
|
|
|
|
SKILL_CATEGORY_UNASSIGNED_KEY,
|
|
|
|
|
|
SKILL_MAIN_UNASSIGNED_KEY,
|
2026-05-20 10:59:17 +02:00
|
|
|
|
skillCatalogPathLabel,
|
|
|
|
|
|
} from './skillCatalogTree.js'
|
|
|
|
|
|
|
|
|
|
|
|
const sample = [
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 1,
|
|
|
|
|
|
name: 'Dachi Waza',
|
|
|
|
|
|
main_category_id: 10,
|
|
|
|
|
|
category_id: 20,
|
|
|
|
|
|
catalog_main_category_name: 'Karate',
|
|
|
|
|
|
catalog_main_sort: 1,
|
|
|
|
|
|
catalog_category_name: 'Kihon',
|
|
|
|
|
|
catalog_category_sort: 2,
|
|
|
|
|
|
sort_order: 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
id: 2,
|
|
|
|
|
|
name: 'Kata Ablauf',
|
|
|
|
|
|
main_category_id: 10,
|
|
|
|
|
|
category_id: 21,
|
|
|
|
|
|
catalog_main_category_name: 'Karate',
|
|
|
|
|
|
catalog_main_sort: 1,
|
|
|
|
|
|
catalog_category_name: 'Kata',
|
|
|
|
|
|
catalog_category_sort: 1,
|
|
|
|
|
|
sort_order: 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
describe('skillCatalogTree', () => {
|
|
|
|
|
|
it('buildSkillCatalogTree groups by main and category', () => {
|
|
|
|
|
|
const tree = buildSkillCatalogTree(sample)
|
|
|
|
|
|
expect(tree).toHaveLength(1)
|
|
|
|
|
|
expect(tree[0].label).toBe('Karate')
|
|
|
|
|
|
expect(tree[0].children).toHaveLength(2)
|
|
|
|
|
|
expect(tree[0].children[0].label).toBe('Kata')
|
2026-05-20 11:18:34 +02:00
|
|
|
|
const kataSkill = tree[0].children[0].children[0]
|
|
|
|
|
|
expect(kataSkill.type).toBe('skill')
|
|
|
|
|
|
expect(kataSkill.skillId).toBe(2)
|
2026-05-20 11:13:34 +02:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-05-20 11:21:18 +02:00
|
|
|
|
it('defaultExpandedKeysForSkillTree opens main groups only', () => {
|
2026-05-20 11:13:34 +02:00
|
|
|
|
const tree = buildSkillCatalogTree(sample)
|
|
|
|
|
|
const keys = defaultExpandedKeysForSkillTree(tree)
|
2026-05-20 11:21:18 +02:00
|
|
|
|
expect(keys).toEqual(['m-10'])
|
|
|
|
|
|
expect(keys.some((k) => k.includes('c-'))).toBe(false)
|
2026-05-20 11:18:34 +02:00
|
|
|
|
expect(keys.some((k) => k.startsWith('s-'))).toBe(false)
|
2026-05-20 10:59:17 +02:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('skillCatalogPathLabel', () => {
|
|
|
|
|
|
expect(skillCatalogPathLabel(sample[0])).toBe('Karate › Kihon › Dachi Waza')
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('collectSkillLeavesFromTree respects exclude', () => {
|
|
|
|
|
|
const tree = buildSkillCatalogTree(sample)
|
|
|
|
|
|
const leaves = collectSkillLeavesFromTree(tree, [1])
|
|
|
|
|
|
expect(leaves).toHaveLength(1)
|
|
|
|
|
|
expect(leaves[0].id).toBe(2)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('filterSkillTreeByQuery', () => {
|
|
|
|
|
|
const tree = buildSkillCatalogTree(sample)
|
|
|
|
|
|
const filtered = filterSkillTreeByQuery(tree, 'dachi')
|
2026-05-20 11:13:34 +02:00
|
|
|
|
const kihon = filtered[0].children.find((c) => c.label === 'Kihon')
|
2026-05-20 11:18:34 +02:00
|
|
|
|
expect(kihon?.children?.some((s) => s.skillId === 1)).toBe(true)
|
2026-05-20 10:59:17 +02:00
|
|
|
|
})
|
2026-05-20 11:16:49 +02:00
|
|
|
|
|
|
|
|
|
|
it('catalogSkillsForSelection lists unassigned buckets', () => {
|
|
|
|
|
|
const skills = [
|
|
|
|
|
|
{ id: 1, main_category_id: null, category_id: null },
|
|
|
|
|
|
{ id: 2, main_category_id: 10, category_id: null },
|
|
|
|
|
|
{ id: 3, main_category_id: 10, category_id: 20 },
|
|
|
|
|
|
]
|
|
|
|
|
|
expect(
|
|
|
|
|
|
catalogSkillsForSelection(skills, SKILL_MAIN_UNASSIGNED_KEY, SKILL_CATEGORY_UNASSIGNED_KEY).map(
|
|
|
|
|
|
(s) => s.id
|
|
|
|
|
|
)
|
|
|
|
|
|
).toEqual([1])
|
|
|
|
|
|
expect(catalogSkillsForSelection(skills, 10, SKILL_CATEGORY_UNASSIGNED_KEY).map((s) => s.id)).toEqual([
|
|
|
|
|
|
2,
|
|
|
|
|
|
])
|
|
|
|
|
|
expect(countCatalogSkillsWithoutMain(skills)).toBe(1)
|
|
|
|
|
|
expect(countCatalogSkillsWithoutCategory(skills, 10)).toBe(1)
|
|
|
|
|
|
})
|
2026-05-20 10:59:17 +02:00
|
|
|
|
})
|