import { describe, expect, it } from "vitest"; import { CINEMAS, findCinemaBySlug, hasVenue, listOtherCinemas, type Cinema, } from "./cinemas"; import { filterCinemas } from "./search"; describe("findCinemaBySlug", () => { it("คืน undefined เมื่อไม่ได้ส่ง slug", () => { expect(findCinemaBySlug(CINEMAS, undefined)).toBeUndefined(); }); it("คืนโรงหนังตาม slug", () => { expect(findCinemaBySlug(CINEMAS, "house-cinema-samyan")?.name).toBe( "HOUSE CINEMA SAMYAN", ); }); }); describe("listOtherCinemas", () => { it("ไม่รวมโรงหนังปัจจุบันและไม่เกิน limit", () => { const others = listOtherCinemas(CINEMAS, "house-cinema-samyan", 4); expect(others).toHaveLength(4); expect(others.map((cinema) => cinema.slug)).not.toContain( "house-cinema-samyan", ); }); }); describe("hasVenue / filterCinemas (ชั้นกรองประเภทโรงหนัง)", () => { const base = { slug: "x", name: "X", tags: ["อาร์ตเฮาส์"], location_label: "", coordinates: null, description: "", map_url: null, address_lines: [], transport: [], contacts: [], payments: [], photos: [], } as Cinema; const local: Cinema = { ...base, slug: "local", venue_type: "โรงภาพยนตร์ท้องถิ่น", }; const indie: Cinema = { ...base, slug: "indie", venue_type: "โรงภาพยนตร์อินดี้" }; const group: Cinema = { ...base, slug: "group", venue_type: "กลุ่มคนฉายหนัง" }; const unset: Cinema = { ...base, slug: "unset" }; it("hasVenue: null = ไม่กรอง", () => { expect(hasVenue(local, null)).toBe(true); expect(hasVenue(unset, null)).toBe(true); }); it("hasVenue: ตรงประเภทเท่านั้น", () => { expect(hasVenue(local, "โรงภาพยนตร์ท้องถิ่น")).toBe(true); expect(hasVenue(local, "โรงภาพยนตร์อินดี้")).toBe(false); expect(hasVenue(unset, "โรงภาพยนตร์อินดี้")).toBe(false); }); it("filterCinemas กรองตามประเภทได้", () => { const all = [local, indie, group, unset]; expect( filterCinemas(all, { category: "ทั้งหมด", query: "", venue: "โรงภาพยนตร์อินดี้", }), ).toEqual([indie]); expect( filterCinemas(all, { category: "ทั้งหมด", query: "", venue: "กลุ่มคนฉายหนัง", }), ).toEqual([group]); expect(filterCinemas(all, { category: "ทั้งหมด", query: "" })).toHaveLength( 4, ); }); it("กรองประเภท + หมวดซ้อนกันได้ (AND)", () => { expect( filterCinemas([local, indie], { category: "อาร์ตเฮาส์", query: "", venue: "โรงภาพยนตร์ท้องถิ่น", }), ).toEqual([local]); }); });