This commit is contained in:
2026-08-05 15:54:59 +08:00
parent eede351038
commit 4b31eb7786
43 changed files with 2117 additions and 851 deletions
@@ -84,17 +84,8 @@ async function mountView(permissions = [
return wrapper
}
async function setFilterContext(wrapper: VueWrapper, customerId = '10001', warehouseId = '') {
async function setWarehouseFilter(wrapper: VueWrapper, warehouseId = '') {
wrapper.findComponent(QueryToolbar).vm.$emit('update:modelValue', {
customerId,
warehouseId: '',
palletCode: '',
palletType: '',
})
await flushPromises()
if (!warehouseId) return
wrapper.findComponent(QueryToolbar).vm.$emit('update:modelValue', {
customerId,
warehouseId,
palletCode: '',
palletType: '',
@@ -103,9 +94,8 @@ async function setFilterContext(wrapper: VueWrapper, customerId = '10001', wareh
}
async function loadRows(wrapper: VueWrapper, warehouseId = '') {
await setFilterContext(wrapper, '10001', warehouseId)
await setWarehouseFilter(wrapper, warehouseId)
wrapper.findComponent(QueryToolbar).vm.$emit('search', {
customerId: '10001',
warehouseId,
palletCode: '',
palletType: '',
@@ -129,33 +119,33 @@ describe('PalletsView', () => {
vi.mocked(createPlatformPallet).mockReset().mockResolvedValue('20002')
})
it('starts with all customers and uses compact semantic filter widths', async () => {
it('starts with all customers and all warehouses using compact filters', async () => {
const wrapper = await mountView()
const toolbar = wrapper.findComponent(QueryToolbar)
const fields = toolbar.props('fields')
expect(toolbar.props('modelValue')).toMatchObject({ customerId: '', warehouseId: '' })
expect(toolbar.props('modelValue')).toMatchObject({ warehouseId: '' })
expect(fields.map((field) => [field.key, field.width])).toEqual([
['customerId', 260],
['warehouseId', 240],
['warehouseId', 300],
['palletCode', 240],
['palletType', 180],
])
expect(wrapper.find('.pallet-filter-toolbar').exists()).toBe(true)
expect(fields.find((field) => field.key === 'customerId')?.placeholder).toBe('全部客户')
expect(listPlatformWarehouses).not.toHaveBeenCalled()
expect(fields.find((field) => field.key === 'warehouseId')?.placeholder).toBe('全部仓库')
expect(listPlatformWarehouses).toHaveBeenCalledWith(undefined, 1, 200)
expect(listPlatformPallets).toHaveBeenCalledWith({
page: 1, size: 20,
})
})
it('loads warehouses after customer selection and omits an empty warehouse id when searching', async () => {
it('loads all warehouses independently and omits an empty warehouse id when searching', async () => {
const wrapper = await mountView()
await loadRows(wrapper)
expect(listPlatformWarehouses).toHaveBeenCalledWith(10001, 1, 200)
expect(listPlatformWarehouses).toHaveBeenCalledTimes(1)
expect(listPlatformWarehouses).toHaveBeenCalledWith(undefined, 1, 200)
expect(listPlatformPallets).toHaveBeenCalledWith({
page: 1, size: 20, tenantId: 10001,
page: 1, size: 20,
})
expect(wrapper.text()).toContain('TP-001')
expect(wrapper.text()).toContain('木托盘')
@@ -165,7 +155,7 @@ describe('PalletsView', () => {
expect(wrapper.text()).not.toContain('启停托盘')
expect(wrapper.text()).not.toContain('全部状态')
expect(wrapper.text()).toContain('全部托盘类型')
expect(wrapper.find('input[aria-label="所属企业"]').exists()).toBe(true)
expect(wrapper.find('input[aria-label="客户"]').exists()).toBe(false)
expect(wrapper.find('input[aria-label="所属仓库"]').exists()).toBe(true)
expect(wrapper.find('.platform-tenant-selector').exists()).toBe(false)
expect(wrapper.text()).not.toContain('租户')
@@ -179,7 +169,7 @@ describe('PalletsView', () => {
const wrapper = await mountView()
const toolbar = wrapper.findComponent(QueryToolbar)
toolbar.vm.$emit('search', { customerId: '', warehouseId: '', palletCode: '', palletType: '' })
toolbar.vm.$emit('search', { warehouseId: '', palletCode: '', palletType: '' })
await flushPromises()
expect(listPlatformPallets).toHaveBeenLastCalledWith({
page: 1, size: 20,
@@ -187,56 +177,49 @@ describe('PalletsView', () => {
})
it('resets customer and dependent warehouse filters without sending an empty id', async () => {
it('resets the warehouse filter without sending an empty id', async () => {
const wrapper = await mountView()
await setFilterContext(wrapper, '10001', '19001')
await setWarehouseFilter(wrapper, '19001')
const toolbar = wrapper.findComponent(QueryToolbar)
toolbar.vm.reset()
await flushPromises()
expect(toolbar.props('modelValue')).toMatchObject({ customerId: '', warehouseId: '' })
expect(toolbar.props('modelValue')).toMatchObject({ warehouseId: '' })
expect(listPlatformPallets).toHaveBeenCalledTimes(2)
expect(listPlatformPallets).toHaveBeenLastCalledWith({
page: 1, size: 20,
})
expect(toolbar.props('fields').find((field) => field.key === 'customerId')?.placeholder).toBe('全部客户')
expect(toolbar.props('fields').find((field) => field.key === 'warehouseId')?.placeholder).toBe('全部仓库')
})
it('preserves a snowflake customer id when switching the enterprise filter', async () => {
it('does not expose customer ownership in warehouse choices', async () => {
const wrapper = await mountView()
const snowflakeId = '9223372036854775806'
const warehouseField = wrapper.findComponent(QueryToolbar).props('fields').find((field) => field.key === 'warehouseId')
wrapper.findComponent(QueryToolbar).vm.$emit('update:modelValue', {
customerId: snowflakeId,
warehouseId: '',
palletCode: '',
palletType: '',
})
await flushPromises()
expect(listPlatformWarehouses).toHaveBeenLastCalledWith(snowflakeId, 1, 200)
expect(listPlatformWarehouses).toHaveBeenCalledTimes(1)
expect(warehouseField?.options).toEqual([{ label: '义乌收货仓(CN-YW-01)', value: '19001' }])
})
it('applies pallet filters only after search', async () => {
const wrapper = await mountView()
await setFilterContext(wrapper, '10001', '19001')
await setWarehouseFilter(wrapper, '19001')
await wrapper.find('input[placeholder="托盘编码(模糊查询)"]').setValue('TP-00')
expect(listPlatformPallets).toHaveBeenCalledTimes(1)
wrapper.findComponent(QueryToolbar).vm.$emit('search', {
customerId: '10001', warehouseId: '19001', palletCode: 'TP-00', palletType: '木托盘',
warehouseId: '19001', palletCode: 'TP-00', palletType: '木托盘',
})
await flushPromises()
expect(listPlatformPallets).toHaveBeenLastCalledWith({
page: 1, size: 20, tenantId: 10001, warehouseId: 19001, palletCode: 'TP-00', palletType: '木托盘',
page: 1, size: 20, warehouseId: 19001, palletCode: 'TP-00', palletType: '木托盘',
})
})
it('creates a pallet in the selected warehouse with the real request fields', async () => {
const wrapper = await mountView()
await setFilterContext(wrapper, '10001', '19001')
await setWarehouseFilter(wrapper, '19001')
const createButton = wrapper.findAll('button').find((button) => button.text().trim() === '新增托盘')
await createButton?.trigger('click')
await flushPromises()
@@ -276,13 +259,13 @@ describe('PalletsView', () => {
expect(wrapper.text()).not.toContain('TP-001')
})
it('stops dependent requests when the enterprise filter cannot load', async () => {
it('keeps platform warehouse and pallet queries available when customer names cannot load', async () => {
vi.mocked(listPlatformCustomers).mockRejectedValueOnce(new Error('Gateway unavailable'))
const wrapper = await mountView()
expect(wrapper.text()).toContain('所属企业列表暂时无法加载')
expect(wrapper.text()).toContain('客户列表暂时无法加载')
expect(wrapper.text()).toContain('重新加载')
expect(listPlatformWarehouses).not.toHaveBeenCalled()
expect(listPlatformWarehouses).toHaveBeenCalledWith(undefined, 1, 200)
expect(listPlatformPallets).toHaveBeenCalledWith({
page: 1, size: 20,
})