- บทความจากหลังบ้าน: /for-film-lovers, /for-cinemas (ArticlePage + ArticleEditor แบบบล็อกย่อหน้า/รูป) - แชร์: ปุ่มบนการ์ดและท้ายหน้ารายละเอียด · ลิงก์ย่อ /c/<slug> (302) · ธีมแก้วตาม DESIGN.md - PWA: manifest/sw/offline + ถอดการล็อกซูม (WCAG 1.4.4) + touch target ≥44px - แอนิเมชัน reveal: IntersectionObserver + gate ด้วย html.fx-motion · เคารพ prefers-reduced-motion - ค้นหา: normalize/ตัดวรรณยุกต์ + AND หลายคำ + จัดอันดับ · รองรับ /?q= จาก SearchAction - SEO: pageMeta (canonical/OG/Twitter) + JSON-LD (WebSite/Organization/BreadcrumbList/MovieTheater/Article) - ไม่ฝังโดเมนในโค้ด: origin มาจาก request (x-forwarded-host/proto) ทั้ง canonical, sitemap, robots, ลิงก์แชร์ - กัน AI: robots.txt (Nitro route, บล็อก AI 21 ตัว) + ai.txt + OG image 1200x630 - เอกสาร: README สรุปโปรเจกต์, DESIGN.md (motion/PWA/SEO/ข้อมูล), architecture.html, admin-guide - tests: 135 ผ่าน (16 ไฟล์)
63 lines
2.3 KiB
TypeScript
63 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { GALLERY_SLOTS, rotateGallery, 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);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("rotateGallery", () => {
|
|
it("ไม่มีรูป → อาร์เรย์ว่าง", () => {
|
|
expect(rotateGallery([], 3)).toEqual([]);
|
|
});
|
|
|
|
it("index 0 คงลำดับเดิม", () => {
|
|
expect(rotateGallery(photosOf(3), 0)).toEqual(photosOf(3));
|
|
});
|
|
|
|
it("index 1 เริ่มที่ภาพที่ 2 และวนภาพแรกไปท้าย", () => {
|
|
expect(rotateGallery(photosOf(4), 1)).toEqual([
|
|
"/images/p2.jpg",
|
|
"/images/p3.jpg",
|
|
"/images/p4.jpg",
|
|
"/images/p1.jpg",
|
|
]);
|
|
});
|
|
|
|
it("index ติดลบและเกินจำนวนวนกลับถูกต้อง", () => {
|
|
expect(rotateGallery(photosOf(3), -1)[0]).toBe("/images/p3.jpg");
|
|
expect(rotateGallery(photosOf(3), 4)[0]).toBe("/images/p2.jpg");
|
|
});
|
|
});
|