Files
admin-web/src/modules/inbounds/weight/components/WeightOcrPanel.test.ts
T
2026-08-04 21:01:39 +08:00

50 lines
2.5 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, preview, OCR retry, correction, confirmation, and server totals', () => {
expect(source).toContain('uploadWeightImage')
expect(source).toContain('downloadWeightImage')
expect(source).toContain('retryWeightRecognition')
expect(source).toContain('correctWeightResult')
expect(source).toContain('confirmWeightResult')
expect(source).toContain('实际总毛重(服务端汇总)')
expect(source).toContain('称重图片序号 #{{ index + 1 }}')
expect(source).toContain('workspace.value?.actualGrossWeightKg')
})
it('matches backend image limits and preserves missing OCR text honestly', () => {
expect(source).toContain("['image/jpeg', 'image/png', 'image/bmp']")
expect(source).toContain('5 * 1024 * 1024')
expect(source).toContain('图片服务未返回 OCR 原文')
expect(source).toContain("adjustmentReason: 'OCR 重试识别结果'")
})
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)')
})
})