36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
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 Team,Alpha 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'],
|
||
);
|
||
});
|