38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
|
|
import { VARIANT_WIDTHS, buildSrcSet, variantS3Key, variantUrl } from "@/lib/image-variants";
|
|
|
|
describe("VARIANT_WIDTHS", () => {
|
|
it("contient 320, 800, 1600", () => {
|
|
expect(VARIANT_WIDTHS).toEqual([320, 800, 1600]);
|
|
});
|
|
});
|
|
|
|
describe("variantUrl", () => {
|
|
it("transforme .jpg en -320.jpg", () => {
|
|
expect(variantUrl("https://x/y/abc.jpg", 320)).toBe("https://x/y/abc-320.jpg");
|
|
});
|
|
it("force JPEG sortie même pour PNG/WebP en input", () => {
|
|
expect(variantUrl("https://x/y/abc.png", 800)).toBe("https://x/y/abc-800.jpg");
|
|
expect(variantUrl("https://x/y/abc.webp", 1600)).toBe("https://x/y/abc-1600.jpg");
|
|
});
|
|
it("renvoie l'original si pas d'extension", () => {
|
|
expect(variantUrl("https://x/y/abc", 320)).toBe("https://x/y/abc");
|
|
});
|
|
});
|
|
|
|
describe("variantS3Key", () => {
|
|
it("transforme correctement la s3Key", () => {
|
|
expect(variantS3Key("carbets/foo/123-abc.jpg", 800)).toBe("carbets/foo/123-abc-800.jpg");
|
|
});
|
|
});
|
|
|
|
describe("buildSrcSet", () => {
|
|
it("contient les 3 variantes + fallback original", () => {
|
|
const set = buildSrcSet("https://x/abc.jpg");
|
|
expect(set).toContain("abc-320.jpg 320w");
|
|
expect(set).toContain("abc-800.jpg 800w");
|
|
expect(set).toContain("abc-1600.jpg 1600w");
|
|
expect(set).toContain("abc.jpg 2000w");
|
|
});
|
|
});
|