23 lines
1.1 KiB
TypeScript
23 lines
1.1 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { bannerExtract } from "./banner-crop";
|
|
import { bannerCropSchema } from "@album/contracts";
|
|
|
|
describe("banner crop", () => {
|
|
test("centers a legacy portrait in exact 8:3", () => {
|
|
expect(bannerExtract(1200, 2400)).toEqual({ left: 0, top: 975, width: 1200, height: 450 });
|
|
});
|
|
test("honors an off-center crop", () => {
|
|
expect(bannerExtract(4000, 3000, { x: 10, y: 20, width: 80, height: 40 })).toEqual({ left: 400, top: 600, width: 3200, height: 1200 });
|
|
});
|
|
test("keeps rounding inside original bounds", () => {
|
|
const crop = bannerExtract(1001, 751, { x: 0, y: 0, width: 100, height: 100 });
|
|
expect(crop.width / crop.height).toBe(8 / 3);
|
|
expect(crop.left + crop.width).toBeLessThanOrEqual(1001);
|
|
expect(crop.top + crop.height).toBeLessThanOrEqual(751);
|
|
});
|
|
test("rejects invalid and empty crops", () => {
|
|
expect(bannerCropSchema.safeParse({ x: 95, y: 0, width: 10, height: 20 }).success).toBe(false);
|
|
expect(() => bannerExtract(1000, 1000, { x: 0, y: 0, width: 0.01, height: 0.01 })).toThrow();
|
|
});
|
|
});
|