form-picker-popup.test.mjs
1.72 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
resolvePickerItemKey,
normalizePickerValues,
buildPickerOptionRows
} = require('../components/form-picker-popup/picker-value.js')
describe('form-picker-popup picker-value', () => {
it('IT-PICKER-001: normalizePickerValues coerces scalar to single-item array', () => {
assert.deepEqual(normalizePickerValues('4s-001'), ['4s-001'])
assert.deepEqual(normalizePickerValues(['4s-001', '4s-002']), ['4s-001', '4s-002'])
assert.deepEqual(normalizePickerValues(null), [])
assert.deepEqual(normalizePickerValues(''), [])
})
it('IT-PICKER-002: buildPickerOptionRows marks active for current value', () => {
const options = [
{ label: '员工A', value: '4s-001' },
{ label: '员工B', value: '4s-002' }
]
const rows = buildPickerOptionRows(options, '4s-002')
assert.equal(rows.length, 2)
assert.equal(rows[0].active, false)
assert.equal(rows[1].active, true)
})
it('IT-PICKER-003: normalizePickerValues resolves object array to ids not [object Object]', () => {
const staff = {
id: '982873a3744e44fbb439432e51edadef',
name: '林永健test003',
phone: '17875511831'
}
assert.equal(resolvePickerItemKey(staff), '982873a3744e44fbb439432e51edadef')
assert.deepEqual(normalizePickerValues([staff]), [
'982873a3744e44fbb439432e51edadef'
])
assert.ok(
!normalizePickerValues([staff]).some(item => item.includes('[object Object]'))
)
const options = [{ label: '林永健test003', value: '982873a3744e44fbb439432e51edadef' }]
const rows = buildPickerOptionRows(options, [staff])
assert.equal(rows[0].active, true)
})
})