优化
This commit is contained in:
@@ -6,17 +6,20 @@ import { ApiResponseError } from '@/shared/api/http'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import {
|
||||
downloadInboundMeasurementImage,
|
||||
getInboundMeasurement,
|
||||
saveInboundMeasurementDraft,
|
||||
submitInboundMeasurement,
|
||||
updateConfirmedPackageCount,
|
||||
} from './api'
|
||||
import type { InboundMeasurementDetail } from './types'
|
||||
import InboundMeasurementPanel from './InboundMeasurementPanel.vue'
|
||||
|
||||
vi.mock('./api', () => ({
|
||||
downloadInboundMeasurementImage: vi.fn(),
|
||||
getInboundMeasurement: vi.fn(),
|
||||
saveInboundMeasurementDraft: vi.fn(),
|
||||
submitInboundMeasurement: vi.fn(),
|
||||
updateConfirmedPackageCount: vi.fn(),
|
||||
}))
|
||||
|
||||
class ResizeObserverStub implements ResizeObserver {
|
||||
@@ -122,7 +125,10 @@ describe('InboundMeasurementPanel', () => {
|
||||
vi.stubGlobal('sessionStorage', createMemoryStorage())
|
||||
document.body.innerHTML = ''
|
||||
vi.mocked(getInboundMeasurement).mockReset().mockResolvedValue(measurement())
|
||||
vi.mocked(saveInboundMeasurementDraft).mockReset().mockResolvedValue({ measurementId: '9001', version: 3, status: 'DRAFT' })
|
||||
vi.mocked(updateConfirmedPackageCount).mockReset().mockResolvedValue({
|
||||
measurementId: '9001', measurementVersion: 3, itemId: '9101',
|
||||
boxCode: 'RK202608040001#10-1', confirmedPackageCount: 10,
|
||||
})
|
||||
vi.mocked(submitInboundMeasurement).mockReset().mockResolvedValue({
|
||||
measurementId: '9001', version: 2, processStatus: 'MEASURE_PENDING', measureReviewStatus: 'PENDING',
|
||||
recommendedPalletType: 'STANDARD', feeId: null, feeNo: null, feeStatus: null,
|
||||
@@ -139,7 +145,10 @@ describe('InboundMeasurementPanel', () => {
|
||||
expect(wrapper.text()).toContain('箱规周长')
|
||||
expect(wrapper.text()).toContain('190 cm')
|
||||
expect(wrapper.text()).toContain('0.6 CBM')
|
||||
expect((wrapper.find('input[placeholder="请输入本箱规的补充说明"]').element as HTMLInputElement).value).toBe('设备自动回传')
|
||||
expect(wrapper.text()).toContain('MJ20210327')
|
||||
const measuredAtInput = wrapper.findAll('label').find((label) => label.text().includes('测量时间'))?.find('input')
|
||||
expect((measuredAtInput?.element as HTMLInputElement).value).toBe('2026-08-04 10:30:00+08:00')
|
||||
expect(wrapper.text()).toContain('预览图片')
|
||||
})
|
||||
|
||||
it('follows the prototype grouping, labels, and editable field order', async () => {
|
||||
@@ -158,11 +167,11 @@ describe('InboundMeasurementPanel', () => {
|
||||
const labels = wrapper.findAll('.measurement-item__grid label > span').map((label) => label.text())
|
||||
expect(labels.slice(0, 8)).toEqual([
|
||||
'箱号',
|
||||
'测量长(cm)*',
|
||||
'测量宽(cm)*',
|
||||
'测量高(cm)*',
|
||||
'测量长(cm)',
|
||||
'测量宽(cm)',
|
||||
'测量高(cm)',
|
||||
'确认箱数 *',
|
||||
'每箱毛重(kg)*',
|
||||
'每箱毛重(kg)',
|
||||
'机器编号',
|
||||
'测量时间',
|
||||
])
|
||||
@@ -176,46 +185,45 @@ describe('InboundMeasurementPanel', () => {
|
||||
expect(wrapper.find('.status-badge').text()).toBe('测量中')
|
||||
})
|
||||
|
||||
it('saves only editable raw fields with the current measurement version', async () => {
|
||||
it('saves only the changed confirmed package count with the current measurement version', async () => {
|
||||
vi.mocked(updateConfirmedPackageCount).mockResolvedValueOnce({
|
||||
measurementId: '9001', measurementVersion: 3, itemId: '9101',
|
||||
boxCode: 'RK202608040001#10-1', confirmedPackageCount: 9,
|
||||
})
|
||||
const wrapper = await mountPanel()
|
||||
await wrapper.find('input[placeholder="请输入实际货物名称"]').setValue('智能音箱')
|
||||
const save = wrapper.findAll('button').find((button) => button.text().includes('保存草稿'))
|
||||
const countInput = wrapper.findAll('label').find((label) => label.text().includes('确认箱数'))?.find('input')
|
||||
await countInput?.setValue('9')
|
||||
const save = wrapper.findAll('button').find((button) => button.text().includes('保存确认箱数'))
|
||||
await save?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(saveInboundMeasurementDraft).toHaveBeenCalledOnce()
|
||||
expect(saveInboundMeasurementDraft).toHaveBeenCalledWith('10001', '7001', expect.objectContaining({
|
||||
measurementId: '9001',
|
||||
version: 2,
|
||||
actualGoodsName: '智能音箱',
|
||||
items: [expect.objectContaining({
|
||||
itemNo: '001', packageCount: 10, lengthCm: 50, intelligentImageFileId: '88001',
|
||||
})],
|
||||
}))
|
||||
const payload = vi.mocked(saveInboundMeasurementDraft).mock.calls[0][2]
|
||||
expect(payload.items[0]).not.toHaveProperty('totalVolumeCbm')
|
||||
expect(updateConfirmedPackageCount).toHaveBeenCalledWith('10001', '7001', '9101', {
|
||||
measurementVersion: 2,
|
||||
confirmedPackageCount: 9,
|
||||
})
|
||||
})
|
||||
|
||||
it('preserves the edited form when the backend reports a version conflict', async () => {
|
||||
vi.mocked(saveInboundMeasurementDraft).mockRejectedValueOnce(
|
||||
vi.mocked(updateConfirmedPackageCount).mockRejectedValueOnce(
|
||||
new ApiResponseError('数据版本已变化,请刷新后重试', 'A0409', 200, null, 'req-conflict', 'trace-conflict'),
|
||||
)
|
||||
const wrapper = await mountPanel()
|
||||
const goodsInput = wrapper.find('input[placeholder="请输入实际货物名称"]')
|
||||
await goodsInput.setValue('保留我的修改')
|
||||
const save = wrapper.findAll('button').find((button) => button.text().includes('保存草稿'))
|
||||
const countInput = wrapper.findAll('label').find((label) => label.text().includes('确认箱数'))?.find('input')
|
||||
await countInput?.setValue('9')
|
||||
const save = wrapper.findAll('button').find((button) => button.text().includes('保存确认箱数'))
|
||||
await save?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('数据版本已变化,当前修改尚未丢失')
|
||||
expect(wrapper.text()).toContain('req-conflict')
|
||||
expect((goodsInput.element as HTMLInputElement).value).toBe('保留我的修改')
|
||||
expect((countInput?.element as HTMLInputElement).value).toBe('9')
|
||||
expect(getInboundMeasurement).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('requires the dirty draft to be saved before submitting for review', async () => {
|
||||
const wrapper = await mountPanel()
|
||||
await wrapper.find('input[placeholder="请输入实际货物名称"]').setValue('尚未保存')
|
||||
const countInput = wrapper.findAll('label').find((label) => label.text().includes('确认箱数'))?.find('input')
|
||||
await countInput?.setValue('9')
|
||||
const submit = wrapper.findAll('button').find((button) => button.text().includes('提交审核'))
|
||||
await submit?.trigger('click')
|
||||
await flushPromises()
|
||||
@@ -250,6 +258,17 @@ describe('InboundMeasurementPanel', () => {
|
||||
expect(submitInboundMeasurement).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('keeps device facts read-only but allows manual count correction after submission', async () => {
|
||||
vi.mocked(getInboundMeasurement).mockResolvedValueOnce(measurement({ processStatus: 'MEASURE_PENDING' }))
|
||||
const wrapper = await mountPanel()
|
||||
const countInput = wrapper.findAll('label').find((label) => label.text().includes('确认箱数'))?.find('input')
|
||||
|
||||
expect((countInput?.element as HTMLInputElement).matches(':disabled')).toBe(false)
|
||||
expect(wrapper.findAll('button').find((button) => button.text().includes('保存确认箱数'))?.attributes('disabled')).toBeUndefined()
|
||||
expect(wrapper.findAll('button').find((button) => button.text().includes('提交审核'))?.attributes('disabled')).toBeDefined()
|
||||
expect(vi.mocked(downloadInboundMeasurementImage)).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('clears the previous customer context before loading the next one', async () => {
|
||||
const wrapper = await mountPanel()
|
||||
vi.mocked(getInboundMeasurement).mockResolvedValueOnce(measurement({ inboundId: '7002', inboundCode: 'RK202608040002', companyName: '第二企业' }))
|
||||
|
||||
Reference in New Issue
Block a user