Files
ftb-project-management/apps/web/lib/task-category.test.ts
2026-06-25 15:21:32 +08:00

39 lines
1.3 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
DEFAULT_TEST_CATEGORY_ID,
PRESET_CATEGORIES,
findCategoryByCode,
getDefaultCategoryByGroup,
normalizeTaskCategories,
resolveCategoryIdFromCode,
} from './task-category';
test('preset categories include stable codes and testing group', () => {
assert.ok(PRESET_CATEGORIES.some((c) => c.code === 'test_functional' && c.group === 'testing'));
assert.ok(PRESET_CATEGORIES.every((c) => c.code.length > 0));
});
test('normalizes legacy categories without code', () => {
const normalized = normalizeTaskCategories([
{ id: 'cat-1', name: '前端开发', group: 'development', sortOrder: 1, isSystem: true },
]);
assert.equal(normalized[0].code, 'frontend_development');
});
test('resolves category id from stable code', () => {
const id = resolveCategoryIdFromCode(PRESET_CATEGORIES, 'test_functional', 'testing');
assert.equal(id, DEFAULT_TEST_CATEGORY_ID);
});
test('falls back to default group category for unknown code', () => {
const category = getDefaultCategoryByGroup(PRESET_CATEGORIES, 'testing');
assert.equal(resolveCategoryIdFromCode(PRESET_CATEGORIES, 'unknown_code', 'testing'), category.id);
});
test('finds category by code', () => {
assert.equal(findCategoryByCode(PRESET_CATEGORIES, 'backend_api')?.name, '后端接口');
});