62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
/** @jest-environment node */
|
|
|
|
import { serializePerformanceSurveyImagePayload } from '@/lib/performance-survey-image-processing'
|
|
import { validatePerformanceSurveyProcessedImages } from '@/lib/performance-survey-processed-images'
|
|
|
|
function slice(width: number) {
|
|
return {
|
|
uploadId: 'work-review-slice',
|
|
mimeType: 'image/webp',
|
|
width,
|
|
height: 1500,
|
|
kind: 'slice',
|
|
sourceName: '作品主视觉.png',
|
|
sourceIndex: 0,
|
|
sliceIndex: 0,
|
|
sliceCount: 1,
|
|
}
|
|
}
|
|
|
|
describe('work review image profile', () => {
|
|
test('keeps the performance survey default width at 1600 pixels', () => {
|
|
expect(() => validatePerformanceSurveyProcessedImages([
|
|
slice(3200),
|
|
])).toThrow('图片宽度无效')
|
|
})
|
|
|
|
test('allows 3200 pixel review slices only when explicitly requested', () => {
|
|
const groups = validatePerformanceSurveyProcessedImages(
|
|
[slice(3200)],
|
|
{ maxSliceWidth: 3200 },
|
|
)
|
|
|
|
expect(groups[0].slices[0].width).toBe(3200)
|
|
expect(() => validatePerformanceSurveyProcessedImages(
|
|
[slice(3201)],
|
|
{ maxSliceWidth: 3200 },
|
|
)).toThrow('图片宽度无效')
|
|
})
|
|
|
|
test('preserves the stable image id used by per-image review comments', () => {
|
|
const payload = serializePerformanceSurveyImagePayload([{
|
|
version: 1,
|
|
imageId: 'image-stable-id',
|
|
sourceName: '作品主视觉.png',
|
|
sourceWidth: 3200,
|
|
sourceHeight: 1500,
|
|
width: 3200,
|
|
height: 1500,
|
|
previewUrl: 'https://s3.example.com/preview.webp',
|
|
previewWidth: 720,
|
|
previewHeight: 338,
|
|
slices: [{
|
|
url: 'https://s3.example.com/slice.webp',
|
|
width: 3200,
|
|
height: 1500,
|
|
}],
|
|
}])
|
|
|
|
expect(payload.imageGroups[0].imageId).toBe('image-stable-id')
|
|
})
|
|
})
|