Files
ftb-project-management/apps/web/lib/requirement-source-target.test.ts
2026-07-02 09:30:50 +08:00

36 lines
1.2 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 test from 'node:test';
import assert from 'node:assert/strict';
import type { SourceTarget } from './requirement';
import {
filterSourceTargetsByKeyword,
formatSourceTargetSelection,
parseSourceTargetSelection,
} from './requirement';
const targets: SourceTarget[] = [
{ id: 'st-1', name: 'Alpha Bank', sourceType: 'customer', createdAt: '2026-07-01' },
{ id: 'st-2', name: 'Beta Retail', sourceType: 'customer', createdAt: '2026-07-01' },
{ id: 'st-3', name: 'Product Team', sourceType: 'internal', createdAt: '2026-07-01' },
];
test('parses and formats requirement source target multi-selection', () => {
assert.deepEqual(parseSourceTargetSelection('Alpha Bank、 Beta Retail, Product TeamAlpha Bank'), [
'Alpha Bank',
'Beta Retail',
'Product Team',
]);
assert.equal(formatSourceTargetSelection(['Alpha Bank', '', 'Beta Retail', 'Alpha Bank']), 'Alpha Bank、Beta Retail');
});
test('filters source targets by source type and keyword', () => {
assert.deepEqual(
filterSourceTargetsByKeyword(targets, 'customer', 'bank').map((target) => target.id),
['st-1'],
);
assert.deepEqual(
filterSourceTargetsByKeyword(targets, 'internal', '').map((target) => target.id),
['st-3'],
);
});