gongxiangp2/lib/__tests__/performance-survey-image-error.test.ts
2026-08-02 01:04:11 +08:00

37 lines
1.2 KiB
TypeScript

import {
isPerformanceSurveyBrowserCapabilityError,
PerformanceSurveyBrowserImageError,
type PerformanceSurveyBrowserImageErrorCode,
} from '@/lib/performance-survey-image-error'
describe('performance-survey-image-error', () => {
test.each<PerformanceSurveyBrowserImageErrorCode>([
'BROWSER_CAPABILITY_UNAVAILABLE',
'BROWSER_DECODE_UNAVAILABLE',
'WORKER_UNAVAILABLE',
'WORKER_TIMEOUT',
'CANVAS_UNAVAILABLE',
'CANVAS_EXPORT_UNAVAILABLE',
])('%s 可进入浏览器能力不足的服务器兜底', (code) => {
expect(isPerformanceSurveyBrowserCapabilityError(
new PerformanceSurveyBrowserImageError(code, '浏览器能力不足'),
)).toBe(true)
})
test.each<PerformanceSurveyBrowserImageErrorCode>([
'SOURCE_FORMAT_UNSUPPORTED',
'SOURCE_DECODE_FAILED',
'SOURCE_DIMENSIONS_INVALID',
'SOURCE_WIDTH_LIMIT',
'SOURCE_PIXEL_LIMIT',
'SOURCE_SLICE_LIMIT',
'SOURCE_COUNT_LIMIT',
'NO_SOURCE_IMAGES',
'PROCESSING_FAILED',
])('%s 必须阻断,不能冒充浏览器兼容问题', (code) => {
expect(isPerformanceSurveyBrowserCapabilityError(
new PerformanceSurveyBrowserImageError(code, '源图或处理策略错误'),
)).toBe(false)
})
})