优化
This commit is contained in:
@@ -40,7 +40,7 @@ const pendingWeight: WeightResultResource = {
|
||||
ocrRawText: '285.5',
|
||||
ocrWeightValue: 285.5,
|
||||
ocrWeightUnit: 'KG',
|
||||
confidence: 0.50972,
|
||||
confidence: 0.98,
|
||||
adjustedWeightValue: null,
|
||||
adjustedWeightUnit: null,
|
||||
finalWeightKg: null,
|
||||
@@ -83,9 +83,11 @@ function mountPanel(permissions = allWeightPermissions) {
|
||||
})
|
||||
}
|
||||
|
||||
async function openWeightDialog(wrapper: VueWrapper) {
|
||||
async function openWeightDialog(wrapper: VueWrapper, reviewEvidence = true) {
|
||||
await wrapper.get('button[aria-label="查看称重图片 1"]').trigger('click')
|
||||
await flushPromises()
|
||||
const evidence = document.body.querySelector<HTMLInputElement>('.ocr-review-check input[type="checkbox"]')
|
||||
if (reviewEvidence && evidence) await new DOMWrapper(evidence).setValue(true)
|
||||
}
|
||||
|
||||
function dialogWeightInput() {
|
||||
@@ -106,6 +108,12 @@ function dialogConfirmButton() {
|
||||
return new DOMWrapper(button)
|
||||
}
|
||||
|
||||
function dialogEvidenceCheckbox() {
|
||||
const input = document.body.querySelector<HTMLInputElement>('.ocr-review-check input[type="checkbox"]')
|
||||
if (!input) throw new Error('OCR evidence checkbox is missing')
|
||||
return new DOMWrapper(input)
|
||||
}
|
||||
|
||||
describe('WeightOcrPanel confirmation behavior', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@@ -191,12 +199,17 @@ describe('WeightOcrPanel confirmation behavior', () => {
|
||||
expect(deleteWeightResult).toHaveBeenCalledWith('10001', '20001', '30001', 0)
|
||||
})
|
||||
|
||||
it('confirms an unchanged OCR value with one request', async () => {
|
||||
it('requires image review before confirming even a high-confidence OCR value', async () => {
|
||||
const wrapper = mountPanel()
|
||||
await flushPromises()
|
||||
await openWeightDialog(wrapper)
|
||||
await openWeightDialog(wrapper, false)
|
||||
|
||||
expect(document.body.textContent).not.toContain('识别重量 285.500 KG')
|
||||
expect(document.body.textContent).toContain('OCR 原文')
|
||||
expect(document.body.textContent).toContain('285.5')
|
||||
expect(document.body.textContent).toContain('98%')
|
||||
expect(document.body.textContent).toContain('OCR 可能误读数字或小数点')
|
||||
expect(dialogConfirmButton().attributes('disabled')).toBeDefined()
|
||||
await dialogEvidenceCheckbox().setValue(true)
|
||||
await dialogConfirmButton().trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
@@ -205,6 +218,28 @@ describe('WeightOcrPanel confirmation behavior', () => {
|
||||
expect(correctWeightResult).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('requires explicit image review before confirming a low-confidence OCR value', async () => {
|
||||
vi.mocked(getWeightWorkspace).mockResolvedValue({
|
||||
...workspace,
|
||||
weightResults: [{ ...pendingWeight, ocrRawText: '5360', ocrWeightValue: 5360, confidence: 0.51863 }],
|
||||
})
|
||||
const wrapper = mountPanel()
|
||||
await flushPromises()
|
||||
await openWeightDialog(wrapper, false)
|
||||
|
||||
expect(document.body.textContent).toContain('OCR 可能误读数字或小数点')
|
||||
expect(document.body.textContent).toContain('OCR 原文')
|
||||
expect(document.body.textContent).toContain('5360')
|
||||
expect(document.body.textContent).toContain('52%')
|
||||
expect(dialogConfirmButton().attributes('disabled')).toBeDefined()
|
||||
|
||||
await dialogEvidenceCheckbox().setValue(true)
|
||||
await dialogConfirmButton().trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(confirmWeightResult).toHaveBeenCalledWith('10001', '20001', '30001', { version: 0 })
|
||||
})
|
||||
|
||||
it('sends the adjusted value and a specific audit reason in the same confirmation request', async () => {
|
||||
const wrapper = mountPanel()
|
||||
await flushPromises()
|
||||
@@ -379,6 +414,7 @@ describe('WeightOcrPanel confirmation behavior', () => {
|
||||
|
||||
expect(dialogConfirmButton().attributes('disabled')).toBeDefined()
|
||||
await dialogWeightInput().setValue('1.500')
|
||||
await dialogEvidenceCheckbox().setValue(true)
|
||||
await dialogConfirmButton().trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user