import test from 'node:test' import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import { createSSRApp } from 'vue' import { renderToString } from 'vue/server-renderer' const source = await readFile(new URL('../src/components/RelabelPalletWork.vue', import.meta.url), 'utf8') const script = source.split('')[0].replace(/^import .*$/gm, '').replace('export default', 'return') function setup() { const calls = [] const component = new Function('ScanTargetInput', 'measureRelabelPallet', 'warehouseIdempotencyKey', 'releaseWarehouseKey', 'bindRelabelPallet', script)( {}, async payload => { calls.push(payload); return [{ palletCode: payload.palletCode, volumeCbm: 0.25, grossWeightKg: payload.grossWeightKg }] }, () => ({ value: 'stable-key', signature: 'signature' }), () => {}, async payload => calls.push(payload)) const value = { ...component.data(), task: { relabelNo: 'RL-1' }, $emit() {} } for (const [key, method] of Object.entries(component.methods)) value[key] = method.bind(value) return { component, value, calls } } test('pallet measurement submits actual dimensions, weight and current stock version and refreshes results', async () => { const { value, calls } = setup() await value.saveMeasurement({ palletCode: 'NEW', stockVersion: 'position:version:count', lengthCm: '100', widthCm: '50', heightCm: '50', grossWeightKg: '40' }) assert.deepEqual(calls, [{ relabelNo: 'RL-1', palletCode: 'NEW', stockVersion: 'position:version:count', lengthCm: 100, widthCm: 50, heightCm: 50, grossWeightKg: 40, idempotencyKey: 'stable-key' }]) assert.equal(value.measurements[0].volumeCbm, 0.25) assert.equal(value.busy, false) await value.saveMeasurement({ palletCode: 'NEW', lengthCm: 0, widthCm: 50, heightCm: 50, grossWeightKg: 40 }) assert.equal(calls.length, 1) assert.match(value.error, /有效/) }) test('only whole physical pallet quantities offer original pallet reuse', () => { const { component } = setup() const canRetain = component.computed.canRetainOriginal const ctx = { source: { totalPackages: 10 }, selectedSource: {}, plannedPackages: 10, isReturnBulk: false, unboundSourceMode: false } assert.equal(canRetain.call(ctx), true) ctx.plannedPackages = 4 assert.equal(canRetain.call(ctx), false) ctx.plannedPackages = 10;ctx.isReturnBulk = true assert.equal(canRetain.call(ctx), false) }) async function renderMeasurements(measurements) { const { component } = setup() const template = source.slice(source.indexOf('