This commit is contained in:
2026-08-27 13:50:41 +08:00
parent 550d8add97
commit 24575223a0
5 changed files with 83 additions and 17 deletions
@@ -72,6 +72,12 @@ const workspace: WeightWorkspaceResource = {
weightResults: [pendingWeight],
}
function palletPage(records = [{
palletId: '50001', palletCode: 'TP-001', palletType: '木托盘', capacityCbm: 1.2, tareWeightKg: 12,
}]) {
return { records, page: 1, size: 20, total: records.length, pages: records.length ? 1 : 0 }
}
enableAutoUnmount(afterEach)
const allWeightPermissions = [
@@ -122,9 +128,7 @@ describe('WeightOcrPanel confirmation behavior', () => {
vi.clearAllMocks()
document.body.innerHTML = ''
vi.mocked(getWeightWorkspace).mockResolvedValue(workspace)
vi.mocked(getWeightPalletOptions).mockResolvedValue([{
palletId: '50001', palletCode: 'TP-001', palletType: '木托盘', capacityCbm: 1.2, tareWeightKg: 12,
}])
vi.mocked(getWeightPalletOptions).mockResolvedValue(palletPage())
vi.mocked(downloadWeightImage).mockResolvedValue(new Blob(['image'], { type: 'image/jpeg' }))
vi.mocked(downloadWeightThumbnail).mockResolvedValue(new Blob(['thumb'], { type: 'image/jpeg' }))
vi.stubGlobal('URL', {
@@ -326,7 +330,7 @@ describe('WeightOcrPanel confirmation behavior', () => {
})
it('shows an actionable empty state when the warehouse has no pallet options', async () => {
vi.mocked(getWeightPalletOptions).mockResolvedValueOnce([])
vi.mocked(getWeightPalletOptions).mockResolvedValueOnce(palletPage([]))
const wrapper = mountPanel()
await flushPromises()
@@ -334,6 +338,28 @@ describe('WeightOcrPanel confirmation behavior', () => {
expect(wrapper.findAll('button').some((button) => button.text().includes('重新加载'))).toBe(true)
})
it('renders records from the formal paged response without showing a load failure', async () => {
vi.mocked(getWeightPalletOptions).mockResolvedValueOnce({
records: [
{ palletId: '2092803000000000001', palletCode: 'TP-11', palletType: '木托盘', capacityCbm: 1.2, tareWeightKg: 12 },
{ palletId: '2092803000000000002', palletCode: 'TP-12', palletType: '塑料托盘', capacityCbm: 1.1, tareWeightKg: 10 },
],
page: 1,
size: 20,
total: 2,
pages: 1,
})
const wrapper = mountPanel()
await flushPromises()
await wrapper.find('.pallet-picker .el-select').trigger('click')
await flushPromises()
expect(document.body.textContent).toContain('木托盘 · 皮重 12.000 KG · 容量 1.2 m³')
expect(document.body.textContent).toContain('塑料托盘 · 皮重 10.000 KG · 容量 1.1 m³')
expect(wrapper.text()).not.toContain('可选托盘加载失败')
})
it('shows pallet loading failures without hiding existing weight results', async () => {
vi.mocked(getWeightPalletOptions).mockRejectedValueOnce(new ApiResponseError('托盘服务暂不可用', 'A0500', 503))
const wrapper = mountPanel()
@@ -373,13 +399,13 @@ describe('WeightOcrPanel confirmation behavior', () => {
})
it('virtualizes one thousand pallet candidates instead of rendering one thousand option nodes', async () => {
vi.mocked(getWeightPalletOptions).mockResolvedValue(Array.from({ length: 1_000 }, (_, index) => ({
vi.mocked(getWeightPalletOptions).mockResolvedValue(palletPage(Array.from({ length: 1_000 }, (_, index) => ({
palletId: String(60_000 + index),
palletCode: `TP-${index}`,
palletType: `托盘类型 ${index}`,
capacityCbm: 1.2,
tareWeightKg: 12,
})))
}))))
const wrapper = mountPanel()
await flushPromises()
@@ -401,9 +427,9 @@ describe('WeightOcrPanel confirmation behavior', () => {
const signal = vi.mocked(getWeightPalletOptions).mock.calls[0]?.[2]
wrapper.unmount()
resolveOptions?.([{
resolveOptions?.(palletPage([{
palletId: 'late', palletCode: 'TP-LATE', palletType: '过期托盘', capacityCbm: 1, tareWeightKg: 10,
}])
}]))
await flushPromises()
expect(signal?.aborted).toBe(true)
@@ -242,8 +242,8 @@ async function loadPalletOptions() {
try {
const result = await getWeightPalletOptions(customerId.value, props.inboundId, controller.signal)
if (sequence !== palletLoadSequence || controller.signal.aborted) return
palletOptions.value = result
if (!result.some((option) => option.palletId === selectedPalletId.value)) selectedPalletId.value = ''
palletOptions.value = result.records
if (!result.records.some((option) => option.palletId === selectedPalletId.value)) selectedPalletId.value = ''
} catch (error) {
if (sequence !== palletLoadSequence || controller.signal.aborted) return
palletOptions.value = []