- แถบกรองสองชั้นในแถวเดียว: ทั้งหมด → 3 ประเภท │ ยอดนิยม → หมวดภาพยนตร์เดิม
- เก็บประเภทที่ฟิลด์เดี่ยว cinema.venue_type (ค่าเดียว) + hasVenue()/filterCinemas({ venue })
- ย้าย "กลุ่มคนฉายหนัง" จาก categories ขึ้นชั้น 1 (ไม่ให้ปุ่มซ้ำ) · tag ยังอยู่และยังค้นหาเจอ
- เลือกได้ทีละชั้น: กดประเภทล้างหมวด / กดหมวดล้างประเภท / ทั้งหมดล้างทั้งคู่
- ปิด popularity path เมื่อกรองด้วยประเภท (กันจัดอันดับข้ามประเภท)
- หลังบ้าน: ช่อง "ประเภทโรงหนัง" ในหมวดข้อมูลหลัก + sanitize เฉพาะค่าใน VENUE_TYPES
- i18n: messages.venues (TH/EN) · override ได้ผ่าน site.terms
- scripts/set-venue-types.mjs จัดประเภท 29 โรง (15 ท้องถิ่น / 11 อินดี้ / 3 กลุ่มคนฉายหนัง) พร้อมสำรอง content.json
- tests: hasVenue + filterCinemas (165 ผ่าน) · sw v2.0.5 · DESIGN/AGENTS/README/admin-guide/api อัปเดต
101 lines
3.2 KiB
TypeScript
101 lines
3.2 KiB
TypeScript
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]);
|
|
});
|
|
});
|