33 lines
1.8 KiB
JavaScript
33 lines
1.8 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
const source = readFileSync(new URL('../src/pages/relabel/relabel.vue', import.meta.url), 'utf8')
|
|
const body = source.split('<script>')[1].split('</script>')[0].replace(/^\s*import .*$/gm, '').replace('export default', 'return')
|
|
function setup(confirm) {
|
|
const calls = []
|
|
const uni = { showModal(options) { calls.push(options); options.success({ confirm }) }, redirectTo(options) { calls.push(options) } }
|
|
const component = new Function('PortalHeader', 'RelabelPalletWork', 'ScanTargetInput', 'uni', body)({}, {}, {}, uni)
|
|
const context = { busy: false, stage: 'receive', taskCode: 'PREVIOUS', error: null, candidates: [{ relabelNo: 'RL-ACTIVE', taskStatus: 'PROCESSING', claimedByCurrentOperator: true }] }
|
|
context.promptActiveTask = component.methods.promptActiveTask.bind(context)
|
|
return { calls, context, open: () => component.methods.openExecution.call(context, { relabelNo: 'RL-OTHER', taskStatus: 'AVAILABLE' }) }
|
|
}
|
|
test('conflicting task opens modal and confirm resumes owned task without claiming another', async () => {
|
|
const { calls, context, open } = setup(true)
|
|
await open()
|
|
assert.equal(calls[0].confirmText, '前往任务')
|
|
assert.equal(calls[0].cancelText, '取消')
|
|
assert.match(calls[0].content, /RL-ACTIVE/)
|
|
assert.equal(context.taskCode, 'RL-ACTIVE')
|
|
assert.equal(calls[1].url, '/pages/relabel/relabel?op=relabelExecute&task=RL-ACTIVE')
|
|
assert.equal(context.error, null)
|
|
assert.equal(context.busy, false)
|
|
})
|
|
test('cancel stays on list and preserves existing task selection', async () => {
|
|
const { calls, context, open } = setup(false)
|
|
await open()
|
|
assert.equal(calls.length, 1)
|
|
assert.equal(context.taskCode, 'PREVIOUS')
|
|
assert.equal(context.busy, false)
|
|
})
|