This commit is contained in:
2026-08-18 11:33:01 +08:00
parent 834382e04b
commit 114d5bacc7
34 changed files with 522 additions and 570 deletions
@@ -68,6 +68,7 @@ const workspace: WeightWorkspaceResource = {
inboundCode: 'RK-20001',
processStatus: 'MEASURING',
actualGrossWeightKg: null,
actualNetWeightKg: null,
weightResults: [pendingWeight],
}
@@ -79,7 +80,7 @@ const allWeightPermissions = [
'platform:firstleg:inbound:weight:confirm',
]
function mountPanel(permissions = allWeightPermissions) {
function mountPanel(permissions = allWeightPermissions, props: Record<string, unknown> = {}) {
const pinia = createPinia()
setActivePinia(pinia)
const auth = useAuthStore()
@@ -88,7 +89,7 @@ function mountPanel(permissions = allWeightPermissions) {
useAccessPreviewStore().initializeAfterLogin()
return mount(WeightOcrPanel, {
attachTo: document.body,
props: { customerId: '10001', inboundId: '20001' },
props: { customerId: '10001', inboundId: '20001', ...props },
global: { plugins: [pinia, ElementPlus] },
})
}
@@ -109,9 +110,9 @@ function dialogUnit(index: number) {
return new DOMWrapper(option)
}
function dialogConfirmButton() {
function dialogConfirmButton(text = '确认重量') {
const button = [...document.body.querySelectorAll<HTMLButtonElement>('.el-dialog__footer button')]
.find((candidate) => candidate.textContent?.trim() === '确认重量')
.find((candidate) => candidate.textContent?.trim() === text)
if (!button) throw new Error('weight confirmation button is missing')
return new DOMWrapper(button)
}
@@ -242,7 +243,8 @@ describe('WeightOcrPanel confirmation behavior', () => {
.mockResolvedValueOnce(workspace)
.mockResolvedValueOnce({
...workspace,
actualGrossWeightKg: 285.5,
actualGrossWeightKg: 1787.5,
actualNetWeightKg: 1747.5,
weightResults: [{ ...pendingWeight, recognitionStatus: 'CONFIRMED', grossWeightKg: 297.5, netWeightKg: 285.5, version: 1 }],
})
const wrapper = mountPanel()
@@ -252,10 +254,53 @@ describe('WeightOcrPanel confirmation behavior', () => {
await dialogConfirmButton().trigger('click')
await flushPromises()
expect(wrapper.emitted('summaryChanged')).toEqual([[285.5]])
expect(wrapper.emitted('summaryChanged')).toEqual([[1787.5, 1747.5]])
expect(wrapper.emitted('changed')).toHaveLength(1)
expect(wrapper.text()).toContain('货物总重量')
expect(wrapper.text()).toContain('285.500 KG')
expect(wrapper.text()).toContain('实测毛重')
expect(wrapper.text()).toContain('货物重量')
expect(wrapper.text()).toContain('1787.500 KG')
expect(wrapper.text()).toContain('1747.500 KG')
})
it('atomically corrects and confirms an approved weight during measurement review', async () => {
const confirmed = {
...pendingWeight,
recognitionStatus: 'CONFIRMED',
adjustedWeightValue: 120,
adjustedWeightUnit: 'KG',
grossWeightKg: 120,
netWeightKg: 108,
version: 1,
}
vi.mocked(getWeightWorkspace).mockResolvedValue({
...workspace,
processStatus: 'MEASURE_PENDING',
actualGrossWeightKg: 120,
actualNetWeightKg: 108,
weightResults: [confirmed],
})
vi.mocked(confirmWeightResult).mockResolvedValue({ ...confirmed, grossWeightKg: 125, netWeightKg: 113, version: 2 })
const wrapper = mountPanel(allWeightPermissions, { reviewMode: true, correctionMode: true })
await flushPromises()
expect(wrapper.find('input[type="file"]').exists()).toBe(false)
expect(wrapper.text()).not.toContain('删除图片')
await wrapper.findAll('button').find((button) => button.text().includes('修改含托盘毛重'))?.trigger('click')
await flushPromises()
await dialogWeightInput().setValue('125')
const reason = document.body.querySelector<HTMLTextAreaElement>('textarea[placeholder="请填写本次毛重修正原因"]')
expect(reason).not.toBeNull()
await new DOMWrapper(reason!).setValue('复核磅秤读数')
await dialogConfirmButton('保存重量修正').trigger('click')
await flushPromises()
expect(confirmWeightResult).toHaveBeenCalledWith('10001', '20001', '30001', {
version: 1,
adjustedWeightValue: 125,
adjustedWeightUnit: 'KG',
adjustmentReason: '复核磅秤读数',
})
expect(correctWeightResult).not.toHaveBeenCalled()
})
it('closes the confirmation dialog immediately after a successful confirmation', async () => {