This commit is contained in:
2026-08-14 19:59:32 +08:00
parent f7594ebd39
commit 1540b80c89
29 changed files with 780 additions and 587 deletions
@@ -4,7 +4,8 @@ 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 DataTable from '@/shared/components/DataTable.vue'
import { downloadWeightImage, downloadWeightThumbnail } from '../weight/api/weightOcr'
import WeightImageThumbnail from '../weight/components/WeightImageThumbnail.vue'
import { approveMeasurement, getMeasurementReviewDetail, listMeasurementReviewHistory, rejectMeasurement } from './api'
import MeasurementReviewPanel from './MeasurementReviewPanel.vue'
@@ -16,6 +17,11 @@ vi.mock('./api', () => ({
releaseRejectedMeasurement: vi.fn(),
}))
vi.mock('../weight/api/weightOcr', () => ({
downloadWeightImage: vi.fn(),
downloadWeightThumbnail: vi.fn(),
}))
const detail = {
inboundId: '90001', inboundCode: 'RK90001', companyName: '柏悦客户', channelCode: 'SEA', channelName: '海运',
processStatus: 'MEASURE_PENDING', measureReviewStatus: 'PENDING', recommendedPalletType: 'STANDARD', reviewReason: null, reviewerId: null, reviewerName: null,
@@ -31,6 +37,11 @@ enableAutoUnmount(afterEach)
describe('MeasurementReviewPanel', () => {
beforeEach(() => {
vi.clearAllMocks()
Object.defineProperty(URL, 'createObjectURL', {
configurable: true,
value: vi.fn((blob: Blob) => blob.size > 5 ? 'blob:weight-original' : 'blob:weight-thumbnail'),
})
Object.defineProperty(URL, 'revokeObjectURL', { configurable: true, value: vi.fn() })
setActivePinia(createPinia())
const auth = useAuthStore()
auth.token = 'token'
@@ -38,31 +49,84 @@ describe('MeasurementReviewPanel', () => {
useAccessPreviewStore().initializeAfterLogin()
vi.mocked(getMeasurementReviewDetail).mockResolvedValue(detail)
vi.mocked(listMeasurementReviewHistory).mockResolvedValue({ records: [], page: 1, size: 20, total: 0, pages: 0 })
vi.mocked(downloadWeightThumbnail).mockResolvedValue(new Blob(['thumb'], { type: 'image/jpeg' }))
vi.mocked(downloadWeightImage).mockResolvedValue(new Blob(['original-image'], { type: 'image/jpeg' }))
})
it('loads and compares original, device and OCR data without exposing a normal fee action', async () => {
it('keeps the review focused on weight evidence and omits carton measurement details', async () => {
const wrapper = mount(MeasurementReviewPanel, { props: { customerId: '10001', inboundId: '90001' }, global: { plugins: [ElementPlus] } })
await flushPromises()
expect(wrapper.text()).toContain('原单申报')
expect(wrapper.text()).toContain('设备实测')
expect(wrapper.text()).toContain('设备采集')
expect(wrapper.text()).not.toContain('DEVICE')
expect(wrapper.text()).toContain('货物总重量')
expect(wrapper.text()).toContain('实测长 × 宽 × 高(cm)')
expect(wrapper.text()).toContain('周长超过渠道限制')
expect(wrapper.text()).toContain('OCR 原文:设备屏幕原始识别内容')
expect(wrapper.text()).toContain('TP-001')
expect(wrapper.text()).toContain('托盘皮重')
expect(wrapper.text()).toContain('入仓码')
expect(wrapper.text()).toContain('RK90001')
expect(wrapper.text()).toContain('柏悦客户 · 海运')
expect(wrapper.text()).toContain('合计货物重量')
expect(wrapper.text()).toContain('全部称重图片')
expect(wrapper.text()).toContain('称重图片')
expect(wrapper.text()).toContain('货物重量')
expect(wrapper.text()).toContain('调整原因:修正 OCR 毛重读数')
expect(wrapper.findComponent(DataTable).exists()).toBe(true)
expect(wrapper.text()).toContain('110 kg')
expect(wrapper.text()).not.toContain('申报毛重')
expect(wrapper.text()).not.toContain('托盘皮重')
expect(wrapper.text()).not.toContain('OCR 原文')
expect(wrapper.text()).not.toContain('设备屏幕原始识别内容')
expect(wrapper.text()).not.toContain('置信度')
expect(wrapper.text()).not.toContain('调整原因')
expect(wrapper.findAllComponents(WeightImageThumbnail)).toHaveLength(1)
expect(wrapper.text()).not.toContain('测量明细')
expect(wrapper.text()).not.toContain('实测长 × 宽 × 高(cm)')
expect(wrapper.text()).not.toContain('设备实测体积')
expect(wrapper.text()).not.toContain('材积重')
expect(wrapper.text()).not.toContain('租户')
expect(wrapper.text()).toContain('通过并进入待分柜')
expect(wrapper.text()).not.toContain('确认费用')
expect(getMeasurementReviewDetail).toHaveBeenCalledWith('10001', '90001')
expect(downloadWeightThumbnail).toHaveBeenCalledWith('10001', '90001', 'file-1')
const source = await import('./MeasurementReviewPanel.vue?raw').then((module) => module.default)
expect(source).toContain('defineExpose({ confirmApprove, openReasonDialog, isPending, isRejected, canReview, canRelease, actionLoading })')
expect(source).not.toContain('measurementColumns')
expect(source.indexOf('全部称重图片')).toBeLessThan(source.indexOf('审核结论'))
expect(source).not.toContain('<DataTable')
expect(source).toContain('<el-collapse class="review-history">')
})
it('shows every weight image at once with its cargo weight below', async () => {
vi.mocked(getMeasurementReviewDetail).mockResolvedValue({
...detail,
actualGrossWeightKg: 330,
weightResults: [
detail.weightResults[0],
{ ...detail.weightResults[0], id: '3', fileId: 'file-2', netWeightKg: 100 },
{ ...detail.weightResults[0], id: '4', fileId: 'file-3', netWeightKg: 120 },
],
})
const wrapper = mount(MeasurementReviewPanel, { props: { customerId: '10001', inboundId: '90001' }, global: { plugins: [ElementPlus] } })
await flushPromises()
expect(wrapper.findAll('.weight-evidence-card')).toHaveLength(3)
expect(wrapper.findAllComponents(WeightImageThumbnail)).toHaveLength(3)
expect(wrapper.findAll('.weight-evidence-card__weight').map((card) => card.text())).toEqual([
'货物重量110 kg',
'货物重量100 kg',
'货物重量120 kg',
])
expect(wrapper.find('.weight-overview').text()).toContain('330 kg')
expect(downloadWeightThumbnail).toHaveBeenCalledTimes(3)
})
it('opens the authenticated original image with the reviewed weight facts', async () => {
const wrapper = mount(MeasurementReviewPanel, { props: { customerId: '10001', inboundId: '90001' }, global: { plugins: [ElementPlus] }, attachTo: document.body })
await flushPromises()
await wrapper.find('.weight-evidence-card .weight-thumb').trigger('click')
await flushPromises()
expect(downloadWeightImage).toHaveBeenCalledWith('10001', '90001', 'file-1')
const preview = document.body.querySelector('.weight-preview')
expect(preview?.textContent).toContain('TP-001 · 木托盘')
expect(preview?.textContent).toContain('120 kg')
expect(preview?.textContent).toContain('10 kg')
expect(preview?.textContent).toContain('110 kg')
expect(preview?.querySelector('img')?.getAttribute('src')).toBe('blob:weight-original')
})
it('shows the rejected release action only when the permission and rejected state exist', async () => {
@@ -107,8 +171,9 @@ describe('MeasurementReviewPanel', () => {
await wrapper.findAll('button').find((button) => button.text().includes('通过并进入待分柜'))?.trigger('click')
await flushPromises()
expect(approveMeasurement).toHaveBeenCalledOnce()
expect(wrapper.emitted('changed')).toHaveLength(1)
expect(wrapper.text()).toContain('初算失败不阻断审核')
expect(wrapper.text()).not.toContain('初算失败不阻断审核')
})
it('rejects with the inbound optimistic-lock version instead of the measurement version', async () => {