Files
admin-web/src/modules/inbounds/weight/components/WeightOcrPanel.test.ts
T
2026-08-07 20:07:37 +08:00

57 lines
3.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("defineProps<{ customerId?: string; tenantId?: string; inboundId: string }>()")
expect(source).toContain("const customerId = computed(() => props.customerId || props.tenantId || '')")
expect(source).toContain("defineEmits<{ changed: [] }>()")
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('downloadWeightImage')
expect(source).toContain('await openPreview(created, URL.createObjectURL(file))')
expect(source).toContain('previewShowsRecognition.value = Boolean(localUrl)')
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('payload.adjustedWeightValue = Number(draft.value)')
expect(source).toContain('payload.adjustmentReason = buildAdjustmentReason(row)')
})
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)')
const template = source.match(/<template>([\s\S]*?)<\/template>/)?.[1] || ''
expect(template).not.toContain('置信度')
expect(template).not.toContain('OCR 原文')
expect(template).not.toContain('提供方')
expect(template).not.toContain('文件 ID')
})
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(['WAIT_MEASURE', 'MEASURING', 'MEASURE_REJECTED'])")
})
it('provides error tracking, empty, loading, and narrow-screen states', () => {
expect(source).toContain('<ApiErrorMeta')
expect(source).toContain('<LoadErrorState')
expect(source).toContain('尚未上传称重图片')
expect(source).toContain('v-loading="loading"')
expect(source).toContain('@media (max-width: 360px)')
})
})