This commit is contained in:
2026-08-13 19:19:34 +08:00
parent 0f0ae612ca
commit df1471dc30
15 changed files with 152 additions and 273 deletions
@@ -117,13 +117,13 @@ describe('PalletsView', () => {
expect(palletsSource).toContain('stripe')
expect(palletsSource).toContain('size="small" plain type="primary"')
expect(palletsSource).toMatch(/size="small"\s+plain\s+type="danger"/)
expect(palletsSource).toContain('<Eye :size="15" />')
expect(palletsSource).not.toContain('<Eye :size="15" />')
expect(palletsSource).toContain('<Pencil :size="15" />')
expect(palletsSource).toContain('<Trash2 :size="15" />')
expect(palletsSource).toContain('@media (max-width: 720px)')
})
it('uses the prototype-sized centered editor while retaining the detail drawer', () => {
expect(palletsSource).toContain('<AppDrawer v-model="detailOpen"')
it('uses the prototype-sized centered editor without an extra detail drawer', () => {
expect(palletsSource).not.toContain('<AppDrawer')
expect(palletsSource).toContain('<AppDialog v-model="editorOpen" :title="editorTitle" width="min(560px, calc(100vw - 28px))"')
expect(palletsSource).not.toContain('<el-drawer v-model="editorOpen"')
expect(palletsSource).toContain(':global(.pallet-editor-dialog .el-dialog__body) { min-height: 0; overflow-y: auto; }')
@@ -243,7 +243,6 @@ describe('PalletsView', () => {
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('编辑')
})
@@ -277,7 +276,7 @@ describe('PalletsView', () => {
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('标准托盘')
await wrapper.find('input[placeholder="选填"]').setValue('标准托盘')
const saveButton = wrapper.findAll('button').find((button) => button.text().trim() === '保存托盘')
await saveButton?.trigger('click')
await flushPromises()
@@ -287,7 +286,7 @@ describe('PalletsView', () => {
})
})
it('groups the pallet editor into clear ownership and specification sections', async () => {
it('uses a compact three-row two-column editor', async () => {
const wrapper = await mountView()
const createButton = wrapper.findAll('button').find((button) => button.text().trim() === '新增托盘')
await createButton?.trigger('click')
@@ -296,9 +295,9 @@ describe('PalletsView', () => {
const editorDialog = document.body.querySelector('.pallet-editor-dialog')
expect(editorDialog?.textContent).toContain('新增托盘')
expect(editorDialog?.querySelector('.el-dialog__title')?.textContent).toBe('新增托盘')
expect(document.body.querySelectorAll('.editor-section')).toHaveLength(2)
expect(document.body.querySelector('#pallet-ownership-heading')?.textContent).toBe('归属仓库')
expect(document.body.querySelector('#pallet-spec-heading')?.textContent).toBe('托盘规格')
expect(document.body.querySelectorAll('.editor-field-grid')).toHaveLength(3)
expect(document.body.querySelector('.editor-section')).toBeNull()
expect(document.body.querySelector('.editor-context')).toBeNull()
expect(document.body.querySelector('.pallet-editor-footer')?.textContent).toContain('为必填项')
})
@@ -309,7 +308,7 @@ describe('PalletsView', () => {
const actions = wrapper.find('.pallet-row-actions').text()
expect(actions).not.toContain('编辑')
expect(actions).not.toContain('删除')
expect(actions).toContain('查看')
expect(actions).not.toContain('查看')
})
it('shows a recoverable list failure instead of demo data', async () => {
@@ -333,59 +332,22 @@ describe('PalletsView', () => {
})
})
it('shows only the pallet fields exposed by the backend contract', async () => {
it('keeps the list limited to fields exposed by the backend contract', async () => {
const publicPallet = { ...pallet, tenantId: '0' }
vi.mocked(listPlatformPallets).mockResolvedValue({ records: [publicPallet], page: 1, size: 20, total: 1, pages: 1 })
vi.mocked(getPlatformPallet).mockResolvedValue(publicPallet)
const wrapper = await mountView()
await loadRows(wrapper)
expect(wrapper.findComponent(DataTable).props('data')).toEqual([publicPallet])
const tableBody = wrapper.find('.el-table__body-wrapper')
const viewButton = tableBody.findAll('.pallet-row-actions button').find((button) => button.text().trim() === '查看')
await viewButton?.trigger('click')
await flushPromises()
expect(getPlatformPallet).toHaveBeenCalledWith(19001, '20001')
expect(document.body.textContent).toContain('资源作用域')
expect(document.body.textContent).toContain('平台公共资源')
expect(document.body.textContent).not.toContain('所属企业')
expect(document.body.textContent).toContain('托盘编码')
expect(document.body.textContent).toContain('托盘类型')
expect(document.body.textContent).toContain('托盘容积')
expect(document.body.textContent).toContain('归属信息')
expect(document.body.textContent).toContain('托盘规格')
expect(document.body.textContent).toContain('记录信息')
expect(document.body.textContent).not.toContain('企业 ID')
expect(document.body.textContent).not.toContain('租户')
expect(document.body.textContent).not.toContain('托盘状态')
expect(document.body.textContent).not.toContain('最大承重')
})
it('keeps the latest detail when an older pallet request finishes last', async () => {
const secondPallet = { ...pallet, id: '20002', palletCode: 'TP-002' }
let resolveFirst!: (value: PlatformPalletResource) => void
let resolveSecond!: (value: PlatformPalletResource) => void
vi.mocked(getPlatformPallet).mockImplementation((_warehouseId, palletId) => new Promise((resolve) => {
if (String(palletId) === String(pallet.id)) resolveFirst = resolve
else resolveSecond = resolve
}))
const wrapper = await mountView()
const vm = wrapper.vm as unknown as {
detailOpen: boolean
detail: PlatformPalletResource | null
openDetail(row: PlatformPalletResource): Promise<void>
}
void vm.openDetail(pallet)
vm.detailOpen = false
await wrapper.vm.$nextTick()
void vm.openDetail(secondPallet)
resolveSecond(secondPallet)
await flushPromises()
resolveFirst(pallet)
await flushPromises()
expect(vm.detail?.palletCode).toBe('TP-002')
const tableText = wrapper.find('.data-table').text()
expect(tableText).toContain('托盘编码')
expect(tableText).toContain('托盘类型')
expect(tableText).toContain('托盘容积')
expect(tableText).not.toContain('所属企业')
expect(tableText).not.toContain('企业 ID')
expect(tableText).not.toContain('租户')
expect(tableText).not.toContain('托盘状态')
expect(tableText).not.toContain('最大承重')
})
it('keeps the latest pallet selected for editing', async () => {