f21-staff-echo.test.mjs
2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
isMultipleSelectIdLikeLabel,
resolveMultipleSelectItemDisplayLabel,
sanitizeMultipleSelectSlashLabel,
hasRealMultipleSelectDisplayNames,
zipMultipleSelectIdsWithDisplayLabel
} = require('../form-engine/multiple-select-display.helpers.js')
describe('F2-1 staff echo (id-only jsonContent)', () => {
it('IT-F21-ECHO-001: dual key with uuid slash label resolves to id array not named objects', () => {
const meta = ['uuid-1', 'uuid-2']
const result = hasRealMultipleSelectDisplayNames(meta, 'uuid-1/uuid-2')
? zipMultipleSelectIdsWithDisplayLabel(meta, 'uuid-1/uuid-2')
: meta.map(id => String(id))
assert.deepEqual(result, ['uuid-1', 'uuid-2'])
})
it('IT-F21-ECHO-001b: dual key with real names still zips id and name', () => {
const meta = ['staff-001', 'staff-002']
assert.equal(hasRealMultipleSelectDisplayNames(meta, '张三/李四'), true)
assert.deepEqual(zipMultipleSelectIdsWithDisplayLabel(meta, '张三/李四'), [
{ id: 'staff-001', name: '张三' },
{ id: 'staff-002', name: '李四' }
])
})
it('IT-F21-ECHO-002: resolveMultipleSelectItemDisplayLabel uses options not uuid fallback', () => {
const options = [
{ label: '张三', value: 'uuid-1', id: 'uuid-1', name: '张三' },
{ label: '李四', value: 'uuid-2', id: 'uuid-2', name: '李四' }
]
const labels = ['uuid-1', 'uuid-2'].map(selectedKey => {
const matched = options.find(item => String(item.value) === selectedKey)
return resolveMultipleSelectItemDisplayLabel({
selectedKey,
rawItem: selectedKey,
matched,
hasOptionsKey: true
})
})
assert.deepEqual(labels, ['张三', '李四'])
assert.equal(
resolveMultipleSelectItemDisplayLabel({
selectedKey: 'uuid-1',
rawItem: 'uuid-1',
matched: null,
hasOptionsKey: true
}),
''
)
})
it('IT-F21-ECHO-002b: sanitizeMultipleSelectSlashLabel strips id-like segments', () => {
assert.equal(
sanitizeMultipleSelectSlashLabel(['uuid-1', 'uuid-2'], 'uuid-1/uuid-2'),
''
)
assert.equal(
sanitizeMultipleSelectSlashLabel(['staff-001', 'staff-002'], '张三/李四'),
'张三/李四'
)
assert.equal(isMultipleSelectIdLikeLabel('uuid-1', 'uuid-1'), true)
assert.equal(isMultipleSelectIdLikeLabel('张三', 'uuid-1'), false)
})
it('IT-F21-ECHO-003: sanitize id-only slash label for jsonContent save', () => {
const ids = ['uuid-1', 'uuid-2']
const displayLabel = sanitizeMultipleSelectSlashLabel(ids, 'uuid-1/uuid-2')
assert.equal(displayLabel, '')
assert.deepEqual(ids, ['uuid-1', 'uuid-2'])
})
})