Files
web-alterflixhub/app/lib/gallery.spec.ts
T
2026-11-01 17:24:44 +07:00

39 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { GALLERY_SLOTS, splitGallery } from "./gallery";
const photosOf = (count: number) =>
Array.from({ length: count }, (_, index) => `/images/p${index + 1}.jpg`);
describe("splitGallery", () => {
it("ไม่มีรูป → ไม่มีภาพหลัก ไม่มีป้าย +N", () => {
expect(splitGallery([])).toEqual({ main: null, thumbs: [], remaining: 0 });
});
it("มีรูป 1 ใบ → เป็นภาพหลัก ไม่มีป้าย", () => {
const view = splitGallery(photosOf(1));
expect(view.main).toBe("/images/p1.jpg");
expect(view.thumbs).toEqual([]);
expect(view.remaining).toBe(0);
});
it("มี 3 ใบ (เท่าจำนวนช่อง) → ไม่มีป้าย +N", () => {
const view = splitGallery(photosOf(GALLERY_SLOTS));
expect(view.thumbs).toHaveLength(2);
expect(view.remaining).toBe(0);
});
it("มี 8 ใบ → แสดง 3 ใบและป้าย +5", () => {
const view = splitGallery(photosOf(8));
expect(view.main).toBe("/images/p1.jpg");
expect(view.thumbs).toEqual(["/images/p2.jpg", "/images/p3.jpg"]);
expect(view.remaining).toBe(5);
});
it("ป้าย +N เท่ากับจำนวนรูปจริงลบช่องที่แสดง", () => {
for (const count of [4, 6, 10, 42]) {
expect(splitGallery(photosOf(count)).remaining).toBe(count - GALLERY_SLOTS);
}
});
});