Files
pda-overseas-uniapp/tests/return-label-confirmation.test.mjs
T
2026-10-12 13:43:37 +08:00

21 lines
1.3 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import vm from 'node:vm'
import { parse, compileScript, compileTemplate } from 'vue/compiler-sfc'
const filename = 'src/components/ReturnLabelConfirmation.vue'
const { descriptor } = parse(readFileSync(new URL('../' + filename, import.meta.url), 'utf8'))
test('physical label confirmation compiles and requires its own barcode before calling the service', async () => {
compileScript(descriptor, { id: 'return-label' })
assert.deepEqual(compileTemplate({ source: descriptor.template.content, filename, id: 'return-label' }).errors, [])
const calls = []
const component = vm.runInNewContext(descriptor.script.content.replace(/^import .*$/gm, '').replace('export default', 'component ='), {
component: null, ScanTargetInput: {}, confirmReturnLabel: async mark => calls.push(mark)
})
const label = { ...component.data(), cartonMark: 'RP-1' }
for (const [name, method] of Object.entries(component.methods)) label[name] = method.bind(label)
await label.confirm('RP-OTHER'); assert.equal(calls.length, 0); assert.equal(label.confirmed, false)
await label.acceptScan('RP-1'); assert.deepEqual(calls, ['RP-1']); assert.equal(label.confirmed, true)
await label.confirm('RP-1'); assert.equal(calls.length, 1)
})