116 lines
3.5 KiB
TypeScript
116 lines
3.5 KiB
TypeScript
import ElementPlus from 'element-plus'
|
|||
|
|
import { createPinia, setActivePinia } from 'pinia'
|
||
|
|
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||
|
|
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||
|
|
import { useAuthStore } from '@/core/auth/auth'
|
||
|
|
import {
|
||
|
|
confirmWeightResult,
|
||
|
|
correctWeightResult,
|
||
|
|
getWeightWorkspace,
|
||
|
|
} from '../api/weightOcr'
|
||
|
|
import type { WeightResultResource, WeightWorkspaceResource } from '../types'
|
||
|
|
import WeightOcrPanel from './WeightOcrPanel.vue'
|
||
|
|
|
||
|
|
vi.mock('../api/weightOcr', async () => {
|
||
|
|
const actual = await vi.importActual<typeof import('../api/weightOcr')>('../api/weightOcr')
|
||
|
|
return {
|
||
|
|
...actual,
|
||
|
|
confirmWeightResult: vi.fn(),
|
||
|
|
correctWeightResult: vi.fn(),
|
||
|
|
getWeightWorkspace: vi.fn(),
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
const pendingWeight: WeightResultResource = {
|
||
|
|
id: '30001',
|
||
|
|
fileId: '40001',
|
||
|
|
ocrProvider: 'FILE_WEIGHT_OCR',
|
||
|
|
ocrRawText: '285.5',
|
||
|
|
ocrWeightValue: 285.5,
|
||
|
|
ocrWeightUnit: 'KG',
|
||
|
|
confidence: 0.50972,
|
||
|
|
adjustedWeightValue: null,
|
||
|
|
adjustedWeightUnit: null,
|
||
|
|
finalWeightKg: null,
|
||
|
|
recognitionStatus: 'PENDING_CONFIRM',
|
||
|
|
adjustmentReason: null,
|
||
|
|
adjustedBy: null,
|
||
|
|
adjustedAt: null,
|
||
|
|
confirmedBy: null,
|
||
|
|
confirmedAt: null,
|
||
|
|
version: 0,
|
||
|
|
}
|
||
|
|
|
||
|
|
const workspace: WeightWorkspaceResource = {
|
||
|
|
inboundId: '20001',
|
||
|
|
inboundCode: 'RK-20001',
|
||
|
|
processStatus: 'MEASURING',
|
||
|
|
actualGrossWeightKg: null,
|
||
|
|
weightResults: [pendingWeight],
|
||
|
|
}
|
||
|
|
|
||
|
|
enableAutoUnmount(afterEach)
|
||
|
|
|
||
|
|
function mountPanel() {
|
||
|
|
const pinia = createPinia()
|
||
|
|
setActivePinia(pinia)
|
||
|
|
const auth = useAuthStore()
|
||
|
|
auth.token = 'token'
|
||
|
|
auth.permissions = [
|
||
|
|
'platform:firstleg:inbound:measure:view',
|
||
|
|
'platform:firstleg:inbound:weight:edit',
|
||
|
|
'platform:firstleg:inbound:weight:confirm',
|
||
|
|
]
|
||
|
|
useAccessPreviewStore().initializeAfterLogin()
|
||
|
|
return mount(WeightOcrPanel, {
|
||
|
|
attachTo: document.body,
|
||
|
|
props: { customerId: '10001', inboundId: '20001' },
|
||
|
|
global: { plugins: [pinia, ElementPlus] },
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
describe('WeightOcrPanel confirmation behavior', () => {
|
||
|
|
beforeEach(() => {
|
||
|
|
vi.clearAllMocks()
|
||
|
|
document.body.innerHTML = ''
|
||
|
|
vi.mocked(getWeightWorkspace).mockResolvedValue(workspace)
|
||
|
|
vi.mocked(confirmWeightResult).mockResolvedValue({
|
||
|
|
...pendingWeight,
|
||
|
|
recognitionStatus: 'CONFIRMED',
|
||
|
|
finalWeightKg: 285.5,
|
||
|
|
version: 1,
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
it('confirms an unchanged OCR value with one request', async () => {
|
||
|
|
const wrapper = mountPanel()
|
||
|
|
await flushPromises()
|
||
|
|
|
||
|
|
await wrapper.get('.weight-row__editor .el-button--success').trigger('click')
|
||
|
|
await flushPromises()
|
||
|
|
|
||
|
|
expect(confirmWeightResult).toHaveBeenCalledTimes(1)
|
||
|
|
expect(confirmWeightResult).toHaveBeenCalledWith('10001', '20001', '30001', { version: 0 })
|
||
|
|
expect(correctWeightResult).not.toHaveBeenCalled()
|
||
|
|
})
|
||
|
|
|
||
|
|
it('sends the adjusted value and a specific audit reason in the same confirmation request', async () => {
|
||
|
|
const wrapper = mountPanel()
|
||
|
|
await flushPromises()
|
||
|
|
|
||
|
|
await wrapper.get('input[aria-label="称重图片序号 1 的确认重量"]').setValue('286.125')
|
||
|
|
await wrapper.get('.weight-row__editor .el-button--success').trigger('click')
|
||
|
|
await flushPromises()
|
||
|
|
|
||
|
|
expect(confirmWeightResult).toHaveBeenCalledTimes(1)
|
||
|
|
expect(confirmWeightResult).toHaveBeenCalledWith('10001', '20001', '30001', {
|
||
|
|
version: 0,
|
||
|
|
adjustedWeightValue: 286.125,
|
||
|
|
adjustedWeightUnit: 'KG',
|
||
|
|
adjustmentReason: 'OCR 原值 285.500 KG,人工确认 286.125 KG',
|
||
|
|
})
|
||
|
|
expect(correctWeightResult).not.toHaveBeenCalled()
|
||
|
|
})
|
||
|
|
})
|