55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
import { computeAlbumLayout } from "./albumLayout";
|
||
|
|
|
||
|
|
describe("computeAlbumLayout", () => {
|
||
|
|
it("returns null for fewer than 2 images", () => {
|
||
|
|
expect(computeAlbumLayout([])).toBeNull();
|
||
|
|
expect(computeAlbumLayout([1.5])).toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
it("places two portraits side by side (1 row, 2 cols)", () => {
|
||
|
|
const layout = computeAlbumLayout([0.7, 0.8])!;
|
||
|
|
expect(layout.gridTemplateRows).toBe("1fr");
|
||
|
|
expect(layout.tiles).toHaveLength(2);
|
||
|
|
// Both tiles occupy the single row, adjacent columns.
|
||
|
|
expect(layout.tiles[0]).toMatchObject({ colStart: 1, colEnd: 2 });
|
||
|
|
expect(layout.tiles[1]).toMatchObject({ colStart: 2, colEnd: 3 });
|
||
|
|
// Album width = sum of ratios when height = 1.
|
||
|
|
expect(layout.aspectRatio).toBeCloseTo(0.7 + 0.8, 4);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("stacks two landscapes vertically (2 rows, 1 col)", () => {
|
||
|
|
const layout = computeAlbumLayout([1.6, 1.4])!;
|
||
|
|
expect(layout.gridTemplateColumns).toBe("1fr");
|
||
|
|
expect(layout.tiles[0]).toMatchObject({ rowStart: 1, rowEnd: 2 });
|
||
|
|
expect(layout.tiles[1]).toMatchObject({ rowStart: 2, rowEnd: 3 });
|
||
|
|
expect(layout.aspectRatio).toBeCloseTo(1 / (1 / 1.6 + 1 / 1.4), 4);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("puts a portrait primary on the left with the rest stacked right", () => {
|
||
|
|
const layout = computeAlbumLayout([0.6, 1.2, 1.3])!;
|
||
|
|
// Primary spans both right-hand rows in column 1.
|
||
|
|
expect(layout.tiles[0]).toEqual({
|
||
|
|
colStart: 1,
|
||
|
|
colEnd: 2,
|
||
|
|
rowStart: 1,
|
||
|
|
rowEnd: 3,
|
||
|
|
});
|
||
|
|
expect(layout.tiles[1]).toMatchObject({ colStart: 2, rowStart: 1 });
|
||
|
|
expect(layout.tiles[2]).toMatchObject({ colStart: 2, rowStart: 2 });
|
||
|
|
});
|
||
|
|
|
||
|
|
it("puts a landscape primary on top with the rest in a row below", () => {
|
||
|
|
const layout = computeAlbumLayout([1.8, 0.9, 1.1])!;
|
||
|
|
// Primary spans both bottom columns in row 1.
|
||
|
|
expect(layout.tiles[0]).toEqual({
|
||
|
|
colStart: 1,
|
||
|
|
colEnd: 3,
|
||
|
|
rowStart: 1,
|
||
|
|
rowEnd: 2,
|
||
|
|
});
|
||
|
|
expect(layout.tiles[1]).toMatchObject({ rowStart: 2, colStart: 1 });
|
||
|
|
expect(layout.tiles[2]).toMatchObject({ rowStart: 2, colStart: 2 });
|
||
|
|
});
|
||
|
|
});
|