2026-08-24 15:41:36 +08:00
|
|
|
import ElementPlus from 'element-plus'
|
|
|
|
|
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
|
|
|
|
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import { listAllPlatformWarehouses } from '@/modules/warehouses'
|
|
|
|
|
import AppDialog from '@/shared/components/AppDialog.vue'
|
|
|
|
|
import QueryToolbar from '@/shared/components/QueryToolbar.vue'
|
2026-08-26 20:39:55 +08:00
|
|
|
import { createPallet, getPallet, listPallets, listReceivingOverseasWarehouses, updatePallet } from '../api/pallets'
|
2026-08-24 15:41:36 +08:00
|
|
|
import PalletsView from './PalletsView.vue'
|
|
|
|
|
|
|
|
|
|
vi.mock('vue-router', () => ({ useRouter: () => ({ push: vi.fn() }) }))
|
|
|
|
|
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: () => true }) }))
|
|
|
|
|
vi.mock('@/modules/warehouses', () => ({ listAllPlatformWarehouses: vi.fn() }))
|
2026-08-26 20:39:55 +08:00
|
|
|
vi.mock('../api/pallets', () => ({ createPallet: vi.fn(), getPallet: vi.fn(), listPallets: vi.fn(), listReceivingOverseasWarehouses: vi.fn(), updatePallet: vi.fn() }))
|
2026-08-24 15:41:36 +08:00
|
|
|
|
|
|
|
|
class ResizeObserverStub implements ResizeObserver { observe() {} unobserve() {} disconnect() {} }
|
|
|
|
|
function memoryStorage(): Storage { const values = new Map<string, string>(); return { get length() { return values.size }, clear: () => values.clear(), getItem: (key) => values.get(key) ?? null, key: (index) => [...values.keys()][index] ?? null, removeItem: (key) => values.delete(key), setItem: (key, value) => values.set(key, value) } }
|
|
|
|
|
enableAutoUnmount(afterEach)
|
|
|
|
|
afterAll(() => vi.unstubAllGlobals())
|
|
|
|
|
|
|
|
|
|
describe('PalletsView', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
|
|
|
|
vi.stubGlobal('localStorage', memoryStorage())
|
2026-08-26 20:39:55 +08:00
|
|
|
vi.mocked(listReceivingOverseasWarehouses).mockReset().mockResolvedValue({ records: [{ id: '200', customerId: '0', warehouseCode: 'LAX', warehouseName: '洛杉矶仓', warehouseType: 'OVERSEAS', status: 'ACTIVE' }], page: 1, size: 200, total: 1, pages: 1 })
|
|
|
|
|
vi.mocked(listAllPlatformWarehouses).mockReset().mockResolvedValue([{ id: '300', warehouseCode: 'ABE3', warehouseName: 'ABE3', warehouseType: 'FBA', status: 'ACTIVE' } as never])
|
|
|
|
|
const pallet = { id: '9007199254740993', customerId: '0', warehouseId: '200', locationId: null, palletCode: 'PLT-1', palletType: 'WOOD', fbaWarehouseCode: 'ABE3', capacityCbm: 2, unitPrice: 10, status: 'IDLE', remark: null, version: 7 }
|
2026-08-24 15:41:36 +08:00
|
|
|
vi.mocked(listPallets).mockReset().mockResolvedValue({ records: [pallet], page: 1, size: 10, total: 1, pages: 1 })
|
|
|
|
|
vi.mocked(getPallet).mockReset().mockResolvedValue(pallet)
|
|
|
|
|
vi.mocked(createPallet).mockReset()
|
|
|
|
|
vi.mocked(updatePallet).mockReset().mockResolvedValue(null)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('loads the current detail version and keeps the edit open on a conflict', async () => {
|
|
|
|
|
vi.mocked(updatePallet).mockRejectedValueOnce(Object.assign(new Error('version conflict'), { code: 'A0409' }))
|
|
|
|
|
const wrapper = mount(PalletsView, { attachTo: document.body, global: { plugins: [ElementPlus] } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
wrapper.findComponent(QueryToolbar).vm.$emit('search', { warehouseId: '200', code: '', type: '', status: '' })
|
|
|
|
|
await flushPromises()
|
2026-08-24 16:57:25 +08:00
|
|
|
await wrapper.findAll('button.el-button--small').filter((button) => button.text().includes('编辑')).at(-1)!.trigger('click')
|
2026-08-24 15:41:36 +08:00
|
|
|
await flushPromises()
|
|
|
|
|
const dialog = wrapper.findComponent(AppDialog)
|
|
|
|
|
dialog.vm.$emit('confirm')
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
expect(getPallet).toHaveBeenCalledWith('200', '9007199254740993')
|
|
|
|
|
expect(updatePallet).toHaveBeenCalledWith('200', '9007199254740993', expect.objectContaining({
|
2026-08-26 20:39:55 +08:00
|
|
|
palletCode: 'PLT-1', fbaWarehouseCode: 'ABE3', version: 7,
|
2026-08-24 15:41:36 +08:00
|
|
|
}))
|
|
|
|
|
expect(dialog.props('modelValue')).toBe(true)
|
|
|
|
|
expect(createPallet).not.toHaveBeenCalled()
|
|
|
|
|
})
|
2026-08-26 20:39:55 +08:00
|
|
|
|
|
|
|
|
it('creates an IDLE ABE3 pallet under the selected Los Angeles warehouse id', async () => {
|
|
|
|
|
vi.mocked(createPallet).mockResolvedValueOnce('9007199254740994')
|
|
|
|
|
const wrapper = mount(PalletsView, { attachTo: document.body, global: { plugins: [ElementPlus] } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
await wrapper.findAll('button').find((button) => button.text().includes('新增托盘'))!.trigger('click')
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
2026-08-30 17:46:45 +08:00
|
|
|
const view = wrapper.vm as unknown as { form: { warehouseId: string; fbaWarehouseCode: string; code: string } }
|
|
|
|
|
Object.assign(view.form, { warehouseId: '200', fbaWarehouseCode: 'ABE3', code: 'PLT-LAX-ABE3' })
|
2026-08-26 20:39:55 +08:00
|
|
|
await flushPromises()
|
|
|
|
|
wrapper.findComponent(AppDialog).vm.$emit('confirm')
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
expect(createPallet).toHaveBeenCalledWith('200', expect.objectContaining({
|
|
|
|
|
palletCode: 'PLT-LAX-ABE3', fbaWarehouseCode: 'ABE3', status: 'IDLE',
|
|
|
|
|
}))
|
|
|
|
|
})
|
2026-08-24 15:41:36 +08:00
|
|
|
})
|