import { describe, expect, it } from 'vitest' import { formCoverAspectRatio } from '@/features/subject-images/layout' import { formFixture, imageFixture } from '@/features/subject-images/testing/fixtures' describe('图库瀑布流图片比例', () => { it.each([ [800, 1200], [1600, 900], [1024, 1024] ])('保留正式图片尺寸 %s × %s', (width, height) => { const form = formFixture() form.images = [imageFixture({ width, height })] expect(formCoverAspectRatio(form)).toBe(`${width} / ${height}`) }) it.each([null, 0, -1, NaN, Infinity])('尺寸 %s 无效时使用稳定占位比例', width => { const form = formFixture() form.images = [imageFixture({ width })] expect(formCoverAspectRatio(form)).toBe('4 / 3') form.images = [imageFixture({ height: width })] expect(formCoverAspectRatio(form)).toBe('4 / 3') }) it('无图片时保留占位,候选封面也使用自己的尺寸', () => { const form = formFixture() form.images = [] expect(formCoverAspectRatio(form)).toBe('4 / 3') form.images = [imageFixture({ isPrimary: false, width: 800, height: 1200 })] expect(formCoverAspectRatio(form)).toBe('800 / 1200') }) })