优化
This commit is contained in:
@@ -4,7 +4,7 @@ import { enableAutoUnmount, flushPromises, mount, type VueWrapper } from '@vue/t
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import { listPlatformWarehouses, type PlatformWarehouseResource } from '@/modules/warehouses'
|
||||
import { listAllPlatformWarehouses, type PlatformWarehouseResource } from '@/modules/warehouses'
|
||||
import DataTable from '@/shared/components/DataTable.vue'
|
||||
import QueryToolbar from '@/shared/components/QueryToolbar.vue'
|
||||
import {
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from '../api/platformPallets'
|
||||
import PalletsView from './PalletsView.vue'
|
||||
|
||||
vi.mock('@/modules/warehouses', () => ({ listPlatformWarehouses: vi.fn() }))
|
||||
vi.mock('@/modules/warehouses', () => ({ listAllPlatformWarehouses: vi.fn() }))
|
||||
vi.mock('../api/platformPallets', () => ({
|
||||
listPlatformPallets: vi.fn(),
|
||||
getPlatformPallet: vi.fn(),
|
||||
@@ -48,9 +48,25 @@ const warehouse: PlatformWarehouseResource = {
|
||||
contactPhone: null, contactEmail: null, status: 'ACTIVE', remark: null,
|
||||
}
|
||||
|
||||
const fbaWarehouse: PlatformWarehouseResource = {
|
||||
...warehouse,
|
||||
id: '19002',
|
||||
warehouseCode: 'FBA-ONT8',
|
||||
warehouseName: 'ONT8 FBA 仓',
|
||||
warehouseType: 'FBA',
|
||||
}
|
||||
|
||||
const overseasWarehouse: PlatformWarehouseResource = {
|
||||
...warehouse,
|
||||
id: '19003',
|
||||
warehouseCode: 'US-LAX-01',
|
||||
warehouseName: '洛杉矶海外仓',
|
||||
warehouseType: 'OVERSEAS',
|
||||
}
|
||||
|
||||
const pallet: PlatformPalletResource = {
|
||||
id: '20001', tenantId: 0, warehouseId: '19001', palletCode: 'TP-001', palletType: '木托盘',
|
||||
capacityCbm: '1.200000', remark: '标准川字托盘', createdAt: '2026-08-04T09:00:00', updatedAt: '2026-08-04T10:00:00',
|
||||
capacityCbm: '1.200000', weightKg: '8.000', color: '黄色', remark: '标准川字托盘', createdAt: '2026-08-04T09:00:00', updatedAt: '2026-08-04T10:00:00',
|
||||
}
|
||||
|
||||
async function mountView(permissions = [
|
||||
@@ -95,13 +111,13 @@ describe('PalletsView', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
document.body.innerHTML = ''
|
||||
vi.mocked(listPlatformWarehouses).mockReset().mockResolvedValue({ records: [warehouse], page: 1, size: 200, total: 1, pages: 1 })
|
||||
vi.mocked(listAllPlatformWarehouses).mockReset().mockResolvedValue([warehouse, fbaWarehouse, overseasWarehouse])
|
||||
vi.mocked(listPlatformPallets).mockReset().mockResolvedValue({ records: [pallet], page: 1, size: 20, total: 1, pages: 1 })
|
||||
vi.mocked(getPlatformPallet).mockReset().mockResolvedValue(pallet)
|
||||
vi.mocked(createPlatformPallet).mockReset().mockResolvedValue('20002')
|
||||
})
|
||||
|
||||
it('starts with all customers and all warehouses using compact filters', async () => {
|
||||
it('starts with all warehouse candidates for querying using compact filters', async () => {
|
||||
const wrapper = await mountView()
|
||||
const toolbar = wrapper.findComponent(QueryToolbar)
|
||||
const fields = toolbar.props('fields')
|
||||
@@ -114,7 +130,12 @@ describe('PalletsView', () => {
|
||||
])
|
||||
expect(wrapper.find('.pallet-filter-toolbar').exists()).toBe(true)
|
||||
expect(fields.find((field) => field.key === 'warehouseId')?.placeholder).toBe('全部仓库')
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledWith(1, 200)
|
||||
expect(fields.find((field) => field.key === 'warehouseId')?.options).toEqual([
|
||||
{ label: '义乌收货仓(CN-YW-01)', value: '19001' },
|
||||
{ label: 'ONT8 FBA 仓(FBA-ONT8)', value: '19002' },
|
||||
{ label: '洛杉矶海外仓(US-LAX-01)', value: '19003' },
|
||||
])
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listPlatformPallets).toHaveBeenCalledWith({
|
||||
page: 1, size: 20,
|
||||
})
|
||||
@@ -124,8 +145,8 @@ describe('PalletsView', () => {
|
||||
const wrapper = await mountView()
|
||||
await loadRows(wrapper)
|
||||
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledTimes(1)
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledWith(1, 200)
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledTimes(1)
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listPlatformPallets).toHaveBeenCalledWith({
|
||||
page: 1, size: 20,
|
||||
})
|
||||
@@ -179,8 +200,24 @@ describe('PalletsView', () => {
|
||||
const wrapper = await mountView()
|
||||
const warehouseField = wrapper.findComponent(QueryToolbar).props('fields').find((field) => field.key === 'warehouseId')
|
||||
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledTimes(1)
|
||||
expect(warehouseField?.options).toEqual([{ label: '义乌收货仓(CN-YW-01)', value: '19001' }])
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledTimes(1)
|
||||
expect(warehouseField?.options).toEqual([
|
||||
{ label: '义乌收货仓(CN-YW-01)', value: '19001' },
|
||||
{ label: 'ONT8 FBA 仓(FBA-ONT8)', value: '19002' },
|
||||
{ label: '洛杉矶海外仓(US-LAX-01)', value: '19003' },
|
||||
])
|
||||
})
|
||||
|
||||
it('does not offer editing for a pallet outside a domestic warehouse', async () => {
|
||||
vi.mocked(listPlatformPallets).mockResolvedValue({
|
||||
records: [{ ...pallet, id: '20002', warehouseId: fbaWarehouse.id }, pallet], page: 1, size: 20, total: 2, pages: 1,
|
||||
})
|
||||
const wrapper = await mountView()
|
||||
|
||||
const bodyRows = wrapper.findAll('.el-table__body-wrapper tbody tr')
|
||||
expect(bodyRows[0]?.text()).toContain('查看')
|
||||
expect(bodyRows[0]?.text()).not.toContain('编辑')
|
||||
expect(bodyRows[1]?.text()).toContain('编辑')
|
||||
})
|
||||
|
||||
it('applies pallet filters only after search', async () => {
|
||||
@@ -206,18 +243,19 @@ describe('PalletsView', () => {
|
||||
await createButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('input[placeholder="例如 TP-001"]').setValue('TP-002')
|
||||
const palletTypeItem = wrapper.findAll('.el-form-item').find((item) => item.text().includes('托盘类型'))
|
||||
palletTypeItem?.findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', '塑料托盘')
|
||||
const capacity = wrapper.findComponent({ name: 'ElInputNumber' })
|
||||
capacity.vm.$emit('update:modelValue', 1.5)
|
||||
await wrapper.find('textarea[placeholder="可填写规格、材质或现场识别说明"]').setValue('蓝色标准托盘')
|
||||
const inputNumbers = wrapper.findAllComponents({ name: 'ElInputNumber' })
|
||||
inputNumbers[0]?.vm.$emit('update:modelValue', 1.5)
|
||||
inputNumbers[1]?.vm.$emit('update:modelValue', 10)
|
||||
await wrapper.find('input[placeholder="例如 黄色"]').setValue('黑色')
|
||||
await wrapper.find('textarea[placeholder="可填写其他说明"]').setValue('标准托盘')
|
||||
const saveButton = wrapper.findAll('button').find((button) => button.text().trim() === '保存托盘')
|
||||
await saveButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(createPlatformPallet).toHaveBeenCalledWith(0, {
|
||||
warehouseId: 19001, palletCode: 'TP-002', palletType: '塑料托盘', capacityCbm: 1.5, remark: '蓝色标准托盘',
|
||||
warehouseId: 19001, palletType: '塑料托盘', capacityCbm: 1.5, weightKg: 10, color: '黑色', remark: '标准托盘',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -264,7 +302,7 @@ describe('PalletsView', () => {
|
||||
|
||||
expect(wrapper.text()).not.toContain('客户列表暂时无法加载')
|
||||
expect(wrapper.text()).not.toContain('所属企业')
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledWith(1, 200)
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listPlatformPallets).toHaveBeenCalledWith({
|
||||
page: 1, size: 20,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user