52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { PrivateAlbumSchema } from "@/data/schemas/private-zone";
|
|
|
|
import {
|
|
findPrivateAlbumDisplayImage,
|
|
getPrivateAlbumDisplayImages,
|
|
getPrivateAlbumGridLayout,
|
|
} from "../private-album-images";
|
|
|
|
describe("private album display images", () => {
|
|
const album = PrivateAlbumSchema.parse({
|
|
albumId: "album-1",
|
|
images: [
|
|
{ url: " /images/photo-1.png ", locked: false, index: 0 },
|
|
{ url: "/images/photo-2.png", locked: true, index: 1 },
|
|
{ url: " ", locked: false, index: 2 },
|
|
{ url: "/images/photo-4.png", locked: false, index: 3 },
|
|
],
|
|
unlocked: true,
|
|
lockDetail: { locked: false },
|
|
});
|
|
|
|
it("filters unavailable images while preserving source indexes", () => {
|
|
expect(getPrivateAlbumDisplayImages(album)).toEqual([
|
|
{ sourceIndex: 0, url: "/images/photo-1.png" },
|
|
{ sourceIndex: 3, url: "/images/photo-4.png" },
|
|
]);
|
|
});
|
|
|
|
it("resolves Gallery images by their original source index", () => {
|
|
expect(findPrivateAlbumDisplayImage(album, 3)).toEqual({
|
|
sourceIndex: 3,
|
|
url: "/images/photo-4.png",
|
|
});
|
|
expect(findPrivateAlbumDisplayImage(album, 1)).toBeNull();
|
|
expect(findPrivateAlbumDisplayImage(album, 2)).toBeNull();
|
|
});
|
|
|
|
it.each([
|
|
[0, "empty"],
|
|
[1, "single"],
|
|
[2, "double"],
|
|
[3, "triple"],
|
|
[4, "double"],
|
|
[5, "triple"],
|
|
[9, "triple"],
|
|
] as const)("uses the expected grid for %i images", (count, layout) => {
|
|
expect(getPrivateAlbumGridLayout(count)).toBe(layout);
|
|
});
|
|
});
|