test: verify pallet label internal code dialog

This commit is contained in:
2026-09-09 18:35:35 +08:00
parent 114def1c11
commit f5a43c1cfe
2 changed files with 59 additions and 1 deletions
@@ -0,0 +1,58 @@
import { mount } from '@vue/test-utils'
import { nextTick } from 'vue'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import PalletLabelPrintDialog from './PalletLabelPrintDialog.vue'
const preparePalletLabels = vi.fn()
vi.mock('../api/platformLoadingLists', () => ({
preparePalletLabels: (...args: unknown[]) => preparePalletLabels(...args),
printPalletLabels: vi.fn(),
}))
describe('PalletLabelPrintDialog', () => {
beforeEach(() => {
preparePalletLabels.mockReset().mockResolvedValue({
planId: '10', planNo: 'LP-1', containerNo: 'HLCU1723867', totalCount: 2,
groups: [{
destinationWarehouseCode: 'ACY2', destinationWarehouseInternalCode: '101',
destinationWarehouseName: 'ACY2', totalCount: 2,
labels: [
{ palletCode: 'HLCU1723867-101-001' },
{ palletCode: 'HLCU1723867-101-002' },
],
}],
})
})
it('shows the server-generated internal code rule and both warehouse codes', async () => {
const wrapper = mount(PalletLabelPrintDialog, {
props: { planId: '10', warehouseId: '20' },
global: {
stubs: {
AppDialog: { template: '<section><slot /></section>' },
LoadErrorState: true,
Printer: true,
'el-button': { template: '<button @click="$emit(\'click\')"><slot /></button>' },
'el-alert': { props: ['title'], template: '<p>{{ title }}</p>' },
'el-radio-group': { template: '<div><slot /></div>' },
'el-radio': { template: '<span><slot /></span>' },
'el-select': { template: '<div><slot /></div>' },
'el-option': true,
'el-input-number': true,
'el-table': { props: ['data'], template: '<div>{{ data }}</div>' },
'el-table-column': true,
},
},
})
await wrapper.get('button').trigger('click')
await nextTick()
await nextTick()
expect(preparePalletLabels).toHaveBeenCalledWith('10', '20')
expect(wrapper.text()).toContain('HLCU1723867-FBA地址内部编号-三位序号')
expect(wrapper.text()).toContain('ACY2')
expect(wrapper.text()).toContain('101')
expect(wrapper.text()).toContain('HLCU1723867-101-001')
})
})
@@ -50,7 +50,7 @@ async function print() {
<AppDialog v-model="open" title="散货托盘码" width="min(760px, calc(100vw - 28px))" confirm-text="生成 PDF" :loading="loading" :confirm-loading="printing" :confirm-disabled="disabledConfirm" @confirm="print">
<LoadErrorState v-if="error" compact title="托盘码操作失败" :message="error.message" :show-retry="false" />
<template v-if="manifest">
<el-alert type="info" :closable="false" :title="`编号规则:${manifest.containerNo}-FBA仓编码-三位序号;一件代发托盘不在此清单。`" />
<el-alert type="info" :closable="false" :title="`编号规则:${manifest.containerNo}-FBA地址内部编号-三位序号;一件代发托盘不在此清单。`" />
<el-radio-group v-model="scope" class="print-scope"><el-radio value="ALL">全部打印({{ manifest.totalCount }} 张)</el-radio><el-radio value="WAREHOUSE">按 FBA 仓补打</el-radio></el-radio-group>
<div v-if="scope === 'WAREHOUSE'" class="print-options"><el-select v-model="warehouseCode" placeholder="选择 FBA 仓" @change="onWarehouseChange"><el-option v-for="group in manifest.groups" :key="group.destinationWarehouseCode" :label="`${group.destinationWarehouseCode} · ${group.totalCount} 张`" :value="group.destinationWarehouseCode" /></el-select><el-input-number v-model="count" placeholder="打印张数" :min="1" :max="selectedGroup?.totalCount || 1" /><span>张(从该仓第 1 张起)</span></div>
<el-table :data="manifest.groups" border max-height="300"><el-table-column label="FBA 仓编码" prop="destinationWarehouseCode" width="140" /><el-table-column label="内部编号" prop="destinationWarehouseInternalCode" width="120" /><el-table-column label="FBA 仓名称" prop="destinationWarehouseName" min-width="160"><template #default="{ row }">{{ row.destinationWarehouseName || '—' }}</template></el-table-column><el-table-column label="托盘数" prop="totalCount" width="90" align="right" /><el-table-column label="编号范围" min-width="230"><template #default="{ row }">{{ row.labels[0]?.palletCode || '—' }}<template v-if="row.labels.length > 1"> ~ {{ row.labels[row.labels.length - 1]?.palletCode }}</template></template></el-table-column></el-table>