feat(fc2c-i): usePolyMasonry shortest-column distribution

This commit is contained in:
2026-05-15 21:10:21 -04:00
parent 6bc7689f6e
commit 61f9401fde
2 changed files with 96 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import { describe, it, expect } from 'vitest'
import { distributeIntoColumns } from '../src/composables/usePolyMasonry.js'
describe('distributeIntoColumns', () => {
it('returns the requested number of columns', () => {
const cols = distributeIntoColumns([], 3)
expect(cols.length).toBe(3)
expect(cols.every(c => c.length === 0)).toBe(true)
})
it('places each item in the then-shortest column', () => {
// 3 square items (relative height 1 each), 3 columns -> one per column.
const items = [
{ id: 1, width: 100, height: 100 },
{ id: 2, width: 100, height: 100 },
{ id: 3, width: 100, height: 100 }
]
const cols = distributeIntoColumns(items, 3)
expect(cols.map(c => c.map(i => i.id))).toEqual([[1], [2], [3]])
})
it('routes a 4th item to a balanced column', () => {
const items = [
{ id: 1, width: 100, height: 300 }, // tall -> col0 height 3
{ id: 2, width: 100, height: 100 }, // col1 height 1
{ id: 3, width: 100, height: 100 }, // col2 height 1
{ id: 4, width: 100, height: 100 } // shortest is col1 (1) -> col1
]
const cols = distributeIntoColumns(items, 3)
expect(cols[0].map(i => i.id)).toEqual([1])
expect(cols[1].map(i => i.id)).toEqual([2, 4])
expect(cols[2].map(i => i.id)).toEqual([3])
})
it('treats missing/zero dimensions as a square (height 1)', () => {
const cols = distributeIntoColumns([{ id: 9 }], 1)
expect(cols[0]).toEqual([{ id: 9 }])
})
})