shinkan-jinkendo/frontend/src/utils/skillCatalogTree.test.js
Lars ab612a5335
All checks were successful
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 12s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m15s
Test Suite / pytest-backend (pull_request) Successful in 35s
Test Suite / lint-backend (pull_request) Successful in 0s
Test Suite / build-frontend (pull_request) Successful in 12s
Test Suite / k6 /health Baseline (pull_request) Successful in 33s
Test Suite / playwright-tests (pull_request) Successful in 1m14s
Update Skill Tree Picker and Catalog Functions for Clarity
- Modified comments in `SkillTreePickerPanel` and `skillCatalogTree.js` to accurately reflect the default expansion behavior, specifying that only main groups are open by default.
- Refactored `defaultExpandedKeysForSkillTree` to simplify the logic, ensuring only main groups are returned as expanded.
- Adjusted tests in `skillCatalogTree.test.js` to validate the updated behavior, confirming that only main groups are opened in the skill tree.
2026-05-20 11:21:18 +02:00

96 lines
3.0 KiB
JavaScript
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 'vitest'
import {
buildSkillCatalogTree,
catalogSkillsForSelection,
collectSkillLeavesFromTree,
countCatalogSkillsWithoutCategory,
countCatalogSkillsWithoutMain,
defaultExpandedKeysForSkillTree,
filterSkillTreeByQuery,
SKILL_CATEGORY_UNASSIGNED_KEY,
SKILL_MAIN_UNASSIGNED_KEY,
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')
const kataSkill = tree[0].children[0].children[0]
expect(kataSkill.type).toBe('skill')
expect(kataSkill.skillId).toBe(2)
})
it('defaultExpandedKeysForSkillTree opens main groups only', () => {
const tree = buildSkillCatalogTree(sample)
const keys = defaultExpandedKeysForSkillTree(tree)
expect(keys).toEqual(['m-10'])
expect(keys.some((k) => k.includes('c-'))).toBe(false)
expect(keys.some((k) => k.startsWith('s-'))).toBe(false)
})
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')
const kihon = filtered[0].children.find((c) => c.label === 'Kihon')
expect(kihon?.children?.some((s) => s.skillId === 1)).toBe(true)
})
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)
})
})