Files
pda-overseas-uniapp/tests/relabel-quick-sku.test.mjs
T
2026-09-17 13:36:08 +08:00

38 lines
2.6 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
const source = await readFile(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')
const component = new Function('PortalHeader', 'RelabelPalletWork', 'ScanTargetInput', body)({}, {}, {})
function context() {
const value = { current: { reviewedAt: null, history: [], items: [{ itemId: '1', operationType: 'CARTON_AND_SKU', expectedPackages: 1, skippedPackages: 0, exceptionPackages: 0, skuProcessedPackages: 0, cartonProcessedPackages: 1, skuItems: [{ skuCode: 'OLD', newSkuCode: 'NEW', quantity: 3 }, { skuCode: 'OTHER', newSkuCode: 'NEW2', quantity: 2 }] }] }, taskTab: 'sku' }
for (const name of ['skuDone', 'skuDetails', 'remaining']) value[name] = component.methods[name].bind(value)
for (const name of ['visibleItems', 'pendingSkuRows']) Object.defineProperty(value, name, { get: component.computed[name].bind(value) })
return value
}
test('each persisted SKU hides independently; mixed carton progress is separate', () => {
const value = context(); assert.equal(value.pendingSkuRows.length, 2)
value.current.history.push({ action: 'SKU_SCAN', detail: JSON.stringify({ round: 'INITIAL', itemId: '1', skuIndex: 0 }) })
assert.equal(value.pendingSkuRows.length, 1); assert.equal(value.pendingSkuRows[0].sku.skuCode, 'OTHER')
value.taskTab = 'carton'; assert.equal(value.visibleItems.length, 0)
value.taskTab = 'sku'; value.current.reviewedAt = '2026-09-15T18:00:00'; assert.equal(value.pendingSkuRows.length, 2)
value.current.items[0].skuProcessedPackages = 1; assert.equal(value.visibleItems.length, 0)
})
test('normal SKU input is always visible in SKU tab and never requests the new label', () => {
assert.match(source, /name="quickSku"/)
assert.doesNotMatch(source, /placeholder="扫描或输入新 SKU 标签号"/)
assert.match(source, /matches.length > 1/)
assert.match(source, /scanRelabelSku/)
})
test('pending list removes one confirmed row at a time without persistent empty or last-scan banners', () => {
const value = context()
assert.equal(value.pendingSkuRows.length, 2)
for (const index of [0, 1]) {
value.current.history.push({ action: 'SKU_SCAN', detail: JSON.stringify({ round: 'INITIAL', itemId: '1', skuIndex: index }) })
assert.equal(value.pendingSkuRows.length, 1 - index)
}
const template = source.split('<script>')[0]
assert.doesNotMatch(template, /待处理明细已清空|v-if="lastSku"|v-if="lastCarton"/)
assert.match(source, /uni.showModal/)
})