29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
|
|
import {
|
||
|
|
describe,
|
||
|
|
expect,
|
||
|
|
it,
|
||
|
|
} from 'vitest';
|
||
|
|
import { fitColumns } from './fitColumns';
|
||
|
|
|
||
|
|
describe('fitColumns', () => {
|
||
|
|
it('packs as many honest columns as fit, gap-aware', () => {
|
||
|
|
// each needs 600, gap 40, available 1280 -> 1 col=600, 2 cols=1240, 3=1880
|
||
|
|
expect(fitColumns({ naturalWidth: 600, available: 1280, gap: 40, maxColumns: 3 })).toBe(2);
|
||
|
|
});
|
||
|
|
it('never exceeds maxColumns even with room', () => {
|
||
|
|
expect(fitColumns({ naturalWidth: 100, available: 5000, gap: 20, maxColumns: 3 })).toBe(3);
|
||
|
|
});
|
||
|
|
it('never returns less than 1', () => {
|
||
|
|
expect(fitColumns({ naturalWidth: 9000, available: 300, gap: 20, maxColumns: 3 })).toBe(1);
|
||
|
|
});
|
||
|
|
it('fits a column at the exact boundary (inclusive)', () => {
|
||
|
|
// 2 cols: 2*600 + 1*40 = 1240 == available -> fits
|
||
|
|
expect(fitColumns({ naturalWidth: 600, available: 1240, gap: 40, maxColumns: 3 })).toBe(2);
|
||
|
|
// one px short -> only 1
|
||
|
|
expect(fitColumns({ naturalWidth: 600, available: 1239, gap: 40, maxColumns: 3 })).toBe(1);
|
||
|
|
});
|
||
|
|
it('respects a maxColumns of 1 even with unlimited room', () => {
|
||
|
|
expect(fitColumns({ naturalWidth: 100, available: 5000, gap: 20, maxColumns: 1 })).toBe(1);
|
||
|
|
});
|
||
|
|
});
|