Files
short-drama-agent-front/tests/features/subject-images/layout.test.ts
T

25 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { masonryColumnCount, masonryRowSpan } from '@/features/subject-images/layout'
describe('图库瀑布流卡片布局', () => {
it('从桌面缩窄到手机时重新按可用宽度计算列数', () => {
expect(masonryColumnCount(2164, 260, 12)).toBe(8)
expect(masonryColumnCount(363, 260, 12)).toBe(1)
expect(masonryColumnCount(240, 260, 12)).toBe(1)
expect(masonryColumnCount(531, 260, 12)).toBe(1)
expect(masonryColumnCount(532, 260, 12)).toBe(2)
})
it('容器尚未布局或尺寸无效时保留单列', () => {
expect(masonryColumnCount(0, 260, 12)).toBe(1)
expect(masonryColumnCount(363, Number.NaN, 12)).toBe(1)
expect(masonryColumnCount(363, 260, -1)).toBe(1)
})
it('按卡片实际高度计算网格跨度', () => {
expect(masonryRowSpan(420, 1, 20)).toBe(21)
expect(masonryRowSpan(421, 1, 20)).toBe(21)
expect(masonryRowSpan(422, 1, 20)).toBe(22)
expect(masonryRowSpan(0, 1, 20)).toBe(1)
})
})