test(client): verify return labels preserve server print templates
This commit is contained in:
@@ -74,13 +74,68 @@ test('退货签收详情使用独立路由和紧凑连续页面', () => {
|
|||||||
assert.doesNotMatch(view, /class="return-detail-dialog"/)
|
assert.doesNotMatch(view, /class="return-detail-dialog"/)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('退货箱唛打印复用统一的紧凑单页模板并按箱分页', () => {
|
// ReturnInventoryService supplies the 100 mm template; the client must preserve
|
||||||
assert.match(view, /@page\{size:100mm 100mm;margin:8mm\}/)
|
// its page margin (8 mm) and content padding (4 mm), including barcode markup.
|
||||||
assert.match(view, /\.label\{width:84mm;height:84mm;padding:8mm/)
|
const labelStyle = '<style>@page{size:100mm 100mm;margin:8mm}.label{width:84mm;height:84mm;padding:4mm;page-break-after:always}.label:last-child{page-break-after:auto}</style>'
|
||||||
assert.match(view, /html\.slice\(contentStart, bodyEnd\)/)
|
const labelHtml = mark => `<!doctype html><html><head>${labelStyle}</head><body><div class="label"><p>${mark}</p><svg data-barcode="${mark}"></svg></div></body></html>`
|
||||||
|
|
||||||
|
function printHarness() {
|
||||||
|
const source = view.slice(view.indexOf('async function printReturnLabel('), view.indexOf('\nfunction openDetail('))
|
||||||
|
.replace('receipt: ReturnReceipt', 'receipt')
|
||||||
|
const calls = { opened: 0, printed: 0, html: '', warnings: [], errors: [], fetched: [] }
|
||||||
|
const popup = {
|
||||||
|
document: { open() {}, write(html) { calls.html = html }, close() {} },
|
||||||
|
focus() {}, print() { calls.printed += 1 }, close() {},
|
||||||
|
}
|
||||||
|
const print = new Function('window', 'ElMessage', 'getReturnInventoryLabel', `${source}; return printReturnLabel`)(
|
||||||
|
{ open() { calls.opened += 1; return popup } },
|
||||||
|
{ warning(message) { calls.warnings.push(message) }, error(message) { calls.errors.push(message) } },
|
||||||
|
async mark => { calls.fetched.push(mark); return { printableHtml: labelHtml(mark) } },
|
||||||
|
)
|
||||||
|
return { print, calls }
|
||||||
|
}
|
||||||
|
|
||||||
|
test('退货箱唛打印保留服务端整份模板,不另行覆盖纸张或条码', async () => {
|
||||||
|
const { print, calls } = printHarness()
|
||||||
|
const printableHtml = labelHtml('RETURN-TEST-1')
|
||||||
|
await print({ cartonMark: 'RETURN-TEST-1', printableHtml })
|
||||||
|
assert.equal(calls.html, printableHtml)
|
||||||
|
assert.equal(calls.printed, 1)
|
||||||
|
assert.deepEqual(calls.fetched, [])
|
||||||
|
assert.deepEqual(calls.errors, [])
|
||||||
|
})
|
||||||
|
|
||||||
|
test('退货多箱打印保留统一模板尺寸和每箱条码,并按箱分页', async () => {
|
||||||
|
const { print, calls } = printHarness()
|
||||||
|
const labels = ['RETURN-TEST-1', 'RETURN-TEST-2'].map(cartonMark => ({ cartonMark, printableHtml: labelHtml(cartonMark) }))
|
||||||
|
await print({ cartonMark: labels[0].cartonMark, labels })
|
||||||
|
assert.equal(calls.html.split(labelStyle).length - 1, 1)
|
||||||
|
assert.equal((calls.html.match(/<html>/g) || []).length, 1)
|
||||||
|
assert.equal((calls.html.match(/<section class="return-label">/g) || []).length, 2)
|
||||||
|
for (const label of labels) assert.ok(calls.html.includes(`<svg data-barcode="${label.cartonMark}"></svg>`))
|
||||||
|
assert.match(calls.html, /\.return-label\{break-after:page\}/)
|
||||||
|
assert.match(calls.html, /\.return-label:last-child\{break-after:auto\}/)
|
||||||
|
assert.match(calls.html, /\.return-label \.label\{page-break-after:auto\}/)
|
||||||
|
assert.equal(calls.printed, 1)
|
||||||
|
assert.deepEqual(calls.fetched, [])
|
||||||
|
assert.deepEqual(calls.errors, [])
|
||||||
assert.match(view, /打印全部箱唛(\{\{ receipt\.labels\?\.length \|\| receipt\.boxCount \|\| 1 \}\} 箱)/)
|
assert.match(view, /打印全部箱唛(\{\{ receipt\.labels\?\.length \|\| receipt\.boxCount \|\| 1 \}\} 箱)/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('缺少内嵌模板时读取鉴权箱唛模板,待修复箱记录禁止打印', async () => {
|
||||||
|
const { print, calls } = printHarness()
|
||||||
|
await print({ cartonMark: 'RETURN-TEST-1' })
|
||||||
|
assert.deepEqual(calls.fetched, ['RETURN-TEST-1'])
|
||||||
|
assert.ok(calls.html.includes(labelStyle))
|
||||||
|
assert.equal(calls.printed, 1)
|
||||||
|
await print({ cartonMark: 'RETURN-TEST-2', labelRepairRequired: true })
|
||||||
|
assert.equal(calls.opened, 1)
|
||||||
|
assert.equal(calls.printed, 1)
|
||||||
|
assert.deepEqual(calls.fetched, ['RETURN-TEST-1'])
|
||||||
|
assert.equal(calls.warnings.length, 1)
|
||||||
|
assert.deepEqual(calls.errors, [])
|
||||||
|
})
|
||||||
|
|
||||||
test('待审核退货可编辑,完成入库后从独立新增页发起贴标', () => {
|
test('待审核退货可编辑,完成入库后从独立新增页发起贴标', () => {
|
||||||
assert.match(view, /row\.status === 'PENDING_REVIEW'.*key: 'edit'/)
|
assert.match(view, /row\.status === 'PENDING_REVIEW'.*key: 'edit'/)
|
||||||
assert.match(view, /if \(editingReturnNo\.value\) await updateReturnOrder\(editingReturnNo\.value, payload\)/)
|
assert.match(view, /if \(editingReturnNo\.value\) await updateReturnOrder\(editingReturnNo\.value, payload\)/)
|
||||||
|
|||||||
Reference in New Issue
Block a user