vin-submit-flush.test.mjs
1.83 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
import { register } from 'node:module'
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
register('./shims/resolve-tilde-loader.mjs', import.meta.url)
describe('vin submit flush', async () => {
it('IT-VIN-FLUSH-001: superseded debounced validateVin rejects cancelled without hanging', async () => {
globalThis.wx = globalThis.wx || {
showToast() {}
}
const { validateVin } = await import('~/utils/vinVaildate.js')
const vin = 'LHGCV1650MH000001'
const first = validateVin(vin).catch(err => err)
await new Promise(resolve => setTimeout(resolve, 20))
validateVin(vin).catch(() => {})
const firstResult = await Promise.race([
first,
new Promise((_, reject) =>
setTimeout(() => reject(new Error('first validateVin hung')), 2000)
)
])
assert.equal(firstResult.cancelled, true)
})
it('IT-VIN-FLUSH-002: buildVinApiValidMapFromEntries merges API results', async () => {
const {
buildVinApiValidMapFromEntries,
listVinScanCellsFromCache
} = await import('../form-engine/vin-api-valid-tracker.js')
const cache = {
'F3-4': [
[
{
key: 'F3-4-8',
type: 'input',
prefixComponent: 'scan',
value: 'LHGCV1650MH000001'
}
]
]
}
const entries = listVinScanCellsFromCache(cache)
assert.equal(entries.length, 1)
const map = await buildVinApiValidMapFromEntries(entries, async () => ({
ok: true,
valid: true
}))
assert.equal(map['F3-4__0__F3-4-8'], true)
})
it('IT-VIN-FLUSH-003: runVinApiValidateImmediate skips debounce', async () => {
const { runVinApiValidateImmediate } = await import(
'../form-engine/vin-api-valid-tracker.js'
)
const result = await runVinApiValidateImmediate(
'SHORT',
async () => ({ success: true }),
{ silent: true }
)
assert.equal(result.ok, true)
assert.equal(result.valid, true)
})
})