This commit is contained in:
2026-11-05 16:03:32 +08:00
parent 63fac79814
commit 1acd33347a
3 changed files with 33 additions and 3 deletions
+24
View File
@@ -130,3 +130,27 @@ test('task list stops carrying a pallet sealed while another ticket was being wo
assert.equal(state.palletNo, '')
assert.ok(!navigations[1].includes('DP-261019-0014'))
})
test('task list hardware scan searches inbound code and releases receiver when hidden', async () => {
const taskSource = await readFile(new URL('../pages/dropship-tasks/dropship-tasks.vue', import.meta.url), 'utf8')
const script = taskSource.match(/<script>([\s\S]*?)<\/script>/)[1].replace(/^\s*import .*$/gm, '').replace('export default', 'globalThis.page =')
let receiver, stopped = 0
const searches = []
const context = { PortalHeader: {}, ScanTargetInput: {}, session: { currentUser: { warehouseId: '100' } }, requireSession: () => true,
startScanBroadcast: options => { receiver = options; return () => { stopped++ } },
listDropshipPalletizationTasks: async (code, warehouse) => { searches.push([code, warehouse]); return [] },
formatApiError: error => error.message }
vm.runInNewContext(script, context)
const state = Object.assign(context.page.data(), context.page.methods)
context.page.onShow.call(state)
await new Promise(resolve => setImmediate(resolve))
receiver.onScan(' IN-2611050001 ')
await new Promise(resolve => setImmediate(resolve))
assert.deepEqual(searches.at(-1), ['IN-2611050001', '100'])
state.loading = true
receiver.onScan('SECOND')
assert.equal(searches.length, 2)
context.page.onHide.call(state)
context.page.onUnload.call(state)
assert.equal(stopped, 1)
})