Files
KArtSell.Aegis/docs/Design/kbx-foundation-v60-status-canonical-contract-hardening/tests/unit/kbx-barcode-capture.contract.spec.ts
T
kjh2064 3f293d8aa8
deploy / deploy (push) Successful in 1m52s
deploy / notify (push) Successful in 1s
V13-FE-006: consolidate approved UI and contract hardening
2026-08-13 02:41:00 +09:00

27 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { isKbxBarcodeDuplicate, normalizeKbxBarcode } from '@kbx/ui'
describe('KbxBarcodeCapture contract', () => {
it('normalizes scanner text but never invents another barcode', () => {
expect(normalizeKbxBarcode(' 8801234567890 ', 'keyboard-wedge', 3, 256, 1)).toEqual({
rawValue: ' 8801234567890 ',
normalizedValue: '8801234567890',
source: 'keyboard-wedge',
occurredAt: 1,
})
})
it('rejects implausibly short and oversized scanner buffers', () => {
expect(normalizeKbxBarcode('A', 'keyboard-wedge', 3, 256, 1)).toBeNull()
expect(normalizeKbxBarcode('123456', 'keyboard-wedge', 3, 5, 1)).toBeNull()
})
it('ignores only the same barcode inside the short device debounce window', () => {
const last=normalizeKbxBarcode('ABC001','keyboard-wedge',3,256,1000)!
const duplicate=normalizeKbxBarcode('ABC001','keyboard-wedge',3,256,1100)!
const legitimateLaterScan=normalizeKbxBarcode('ABC001','keyboard-wedge',3,256,1400)!
expect(isKbxBarcodeDuplicate(duplicate,last,180)).toBe(true)
expect(isKbxBarcodeDuplicate(legitimateLaterScan,last,180)).toBe(false)
})
})