This commit is contained in:
2026-11-05 17:46:01 +08:00
parent 40095a749b
commit 8d80074266
6 changed files with 61 additions and 4 deletions
@@ -0,0 +1,32 @@
import { shallowMount, flushPromises } from '@vue/test-utils'
import { beforeEach, expect, it, vi } from 'vitest'
import Dialog from './LooseboardCargoDialog.vue'
import { candidate, detail } from '../../overseas-warehouse/dispatchTestFixtures'
import * as api from '@/modules/overseas-warehouse'
vi.mock('@/modules/overseas-warehouse', async () => ({
getDispatch: vi.fn(), listLooseboardCargo: vi.fn(), addLooseboardCargo: vi.fn(),
expandSelectionGroups: (await import('../../overseas-warehouse/dispatchContracts')).expandSelectionGroups,
}))
vi.mock('element-plus', () => ({ ElMessage: { success: vi.fn() } }))
beforeEach(() => { vi.clearAllMocks() })
it('selects one looseboard order and submits all original pallet selections together', async () => {
const first = candidate({ orderNo: 'LB1', availablePackages: 9 })
const second = candidate({ sourceKey: 'source-2', sourceVersion: 'version-2', selection: { ...first.selection, planPalletId: '2', sourceVersion: 'version-2' } })
first.selectionGroup = { ...first.selectionGroup, sources: [...first.selectionGroup.sources, ...second.selectionGroup.sources], pallets: [...first.selectionGroup.pallets, { warehousePalletId: null, palletNo: 'P2', sourceKeys: [second.sourceKey], packageCount: 2 }] }
const dispatch = detail(); dispatch.actions.ADD_CARGO = { allowed: true, blockCode: null, blockReason: null }
vi.mocked(api.getDispatch).mockResolvedValue(dispatch)
vi.mocked(api.listLooseboardCargo).mockResolvedValue({ candidates: [first], total: 1, page: 1, size: 20, pages: 1, complete: true, snapshotAt: '2026-11-05T00:00:00Z' })
const wrapper = shallowMount(Dialog, { props: { modelValue: false, dispatchNo: 'PC/1' }, global: { renderStubDefaultSlot: true, stubs: { ElAlert: true } } })
await wrapper.setProps({ modelValue: true }); await flushPromises()
const table = wrapper.getComponent({ name: 'DataTable' })
expect(table.props('data')).toHaveLength(1)
expect(table.props('columns').map((column: { label?: string }) => column.label)).toContain('托数')
expect(table.props('columns').map((column: { label?: string }) => column.label)).not.toContain('计划 / 实物托盘')
table.vm.$emit('selection-change', [first]); await flushPromises()
wrapper.getComponent({ name: 'AppDialog' }).vm.$emit('confirm'); await flushPromises()
expect(api.addLooseboardCargo).toHaveBeenCalledWith('PC/1', expect.objectContaining({ cargo: [first.selection, second.selection] }))
expect(wrapper.emitted('update:modelValue')).toEqual([[false]])
wrapper.unmount()
})