Files
admin-web/src/modules/inbounds/weight/components/WeightOcrPanel.test.ts
T
2026-09-14 17:54:21 +08:00

106 lines
6.0 KiB
TypeScript

import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
const source = readFileSync(resolve(process.cwd(), 'src/modules/inbounds/weight/components/WeightOcrPanel.vue'), 'utf8')
describe('WeightOcrPanel contract', () => {
it('uses customer language at the page boundary while retaining a compatibility input', () => {
expect(source).toContain('reviewMode?: boolean')
expect(source).toContain("const customerId = computed(() => props.customerId || props.tenantId || '')")
expect(source).toContain('summaryChanged: [actualGrossWeightKg: number | null, actualNetWeightKg: number | null, hasConfirmedWeight: boolean]')
expect(source).toContain("defineExpose({ reload: loadWorkspace })")
const template = source.match(/<template>([\s\S]*?)<\/template>/)?.[1] || ''
expect(template).not.toContain('租户')
})
it('covers upload, immediate preview, inline correction, deletion, confirmation, and server totals', () => {
expect(source).toContain('uploadWeightImage')
expect(source).toContain('getWeightPalletOptions')
expect(source).toContain('palletId: selectedPalletId.value')
expect(source).toContain('downloadWeightImage')
expect(source).toContain('await openPreview(created, URL.createObjectURL(file))')
expect(source).toContain('deleteWeightResult')
expect(source).toContain('confirmWeightResult')
expect(source).toContain('class="weight-card__value"')
expect(source).toContain('v-model="weightDrafts[previewResult.id].value"')
expect(source).toContain('当前托盘皮重')
expect(source).toContain("previewResult.palletType || '未记录类型'")
expect(source).toContain('OCR 识别毛重')
expect(source).toContain('确认含托盘毛重')
expect(source).toContain('payload.adjustedWeightValue = Number(draft.value)')
expect(source).toContain("row.recognitionStatus === 'CONFIRMED' && reviewCorrectionEnabled.value")
expect(source).toContain('draft.reason.trim()')
expect(source).toContain('实测毛重')
expect(source).toContain('货物重量')
expect(source).toContain('palletTareWeightKg')
expect(source).toContain('netWeightKg')
expect(source).toContain('row.locationCode')
expect(source).toContain('row.sharedOverflow')
expect(source).toContain('putawayStatusLabel(row.slotStatus)')
expect(source).not.toContain('class="putaway-guide"')
expect(source).not.toContain('整票上架引导')
expect(source).not.toContain('整票预留库位')
expect(source).not.toContain('尚未分配整票预留库位')
expect(source).not.toContain('class="weight-card__putaway"')
expect(source).toContain('<div><dt>库位</dt><dd')
expect(source).not.toContain('workspace.palletLocationGuide.slots')
expect(source).toContain('对应库位仍为本票保留,不会释放给其他订单')
expect(source).toContain("workspace.value?.weightResults.some((item) => item.recognitionStatus === 'CONFIRMED') === true")
})
it('matches backend image limits and keeps technical OCR data out of the list', () => {
expect(source).toContain("['image/jpeg', 'image/png', 'image/bmp']")
expect(source).toContain('5 * 1024 * 1024')
expect(source).toContain('ocrRawText: getWeightOcrRawText(upload)')
expect(source).not.toContain('ocr-review-check')
expect(source).not.toContain('OCR 可能误读数字或小数点')
expect(source).not.toContain('<span>置信度</span>')
expect(source).not.toContain('<span>OCR 原文</span>')
expect(source).not.toContain('<span>托盘编码</span>')
expect(source).toContain('<span>托盘类型</span>')
expect(source).not.toContain('<span>托盘容量</span>')
expect(source).not.toContain('<span>服务端毛重</span>')
expect(source).not.toContain('<span>服务端净重</span>')
expect(source).not.toContain('`${option.palletCode} · ${option.palletType}`')
expect(source).toContain("option.palletType || '未记录类型'")
})
it('keeps pallet type, tare weight, and capacity in one virtualized select line', () => {
expect(source).toContain('<el-select-v2')
expect(source).toContain(':options="virtualPalletOptions"')
expect(source).toContain('label: palletOptionLabel(option)')
expect(source).toContain("`${option.palletType || '未记录类型'} · 皮重 ${formatWeight(option.tareWeightKg)} · 容量 ${option.capacityCbm} m³`")
expect(source).not.toContain('<small v-if="selectedPallet">')
expect(source).toContain('width: clamp(360px, 36vw, 520px)')
})
it('gates every action with the implemented permissions and editable statuses', () => {
expect(source).toContain("platform:firstleg:inbound:measure:view")
expect(source).toContain("platform:firstleg:inbound:weight:edit")
expect(source).toContain("platform:firstleg:inbound:weight:confirm")
expect(source).toContain("new Set(['PREPARING', 'WAIT_MEASURE', 'MEASURING', 'MEASURE_REJECTED'])")
expect(source).toContain('&& canEdit.value')
expect(source).toContain('&& editable.value')
expect(source).toContain('cancelPalletOptionsLoad()')
expect(source).toContain("workspace.value?.processStatus === 'MEASURE_PENDING'")
expect(source).toContain('v-if="canEdit && !reviewMode"')
expect(source).toContain('v-if="canEdit && editable && !reviewMode"')
})
it('provides error tracking, empty, loading, and narrow-screen states', () => {
expect(source).toContain('<ApiErrorMeta')
expect(source).toContain('<LoadErrorState')
expect(source).toContain('尚未上传称重图片')
expect(source).not.toContain('称重数据仅供查看')
expect(source).toContain('v-loading="loading"')
expect(source).toContain('@media (max-width: 720px)')
expect(source).toContain('@media (max-width: 360px)')
})
it('keeps each weight summary label and value on one compact line', () => {
expect(source).toContain('.weight-summary { display: flex; align-items: baseline; gap: var(--admin-space-2, 6px); white-space: nowrap; }')
expect(source).not.toContain('.weight-summary { display: grid;')
})
})