- ลิสต์โรงหนัง: ช่องค้นหา (ไทย/อังกฤษ/slug) + ชิปกรองประเภทพร้อมจำนวน (ทั้งหมด/ท้องถิ่น/อินดี้/กลุ่ม/ยังไม่จัด) - ป้ายประเภทท้ายชื่อทุกแถว (ยังไม่จัด = ป้ายแดง) + empty state - ตั้งประเภททีละกลุ่ม: "ตั้งประเภทให้ N โรงที่กรองอยู่" → เลือกประเภท → ใช้ (แล้วกดบันทึกทั้งหมด) - หัวหลังบ้านสรุปจำนวนต่อประเภท - แท็บคำศัพท์: ปุ่มลัดสร้าง key `venues.<ประเภท>` สำหรับแปลชื่อตัวกรอง - ปิดลากสลับลำดับขณะกรอง + hint อธิบาย - logic ย้ายไป lib: filterAdminCinemas / setVenueForSlugs / venueCounts + unit tests (169 ผ่าน) - DESIGN.md / docs/admin-guide.md อัปเดต
188 lines
6.3 KiB
TypeScript
188 lines
6.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
CINEMAS,
|
|
findCinemaBySlug,
|
|
hasVenue,
|
|
listOtherCinemas,
|
|
type Cinema,
|
|
filterAdminCinemas,
|
|
setVenueForSlugs,
|
|
venueCounts,
|
|
} 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]);
|
|
});
|
|
});
|
|
|
|
describe("หลังบ้าน: ตัวกรองประเภทโรงหนัง", () => {
|
|
const base = {
|
|
slug: "base",
|
|
name: "X",
|
|
tags: [],
|
|
location_label: "",
|
|
coordinates: null,
|
|
description: "",
|
|
map_url: null,
|
|
address_lines: [],
|
|
transport: [],
|
|
contacts: [],
|
|
payments: [],
|
|
photos: [],
|
|
} as Cinema;
|
|
const list: Cinema[] = [
|
|
{
|
|
...base,
|
|
slug: "a-local",
|
|
name: "Alpha",
|
|
name_th: "อัลฟา",
|
|
venue_type: "โรงภาพยนตร์ท้องถิ่น",
|
|
},
|
|
{ ...base, slug: "b-indie", name: "Beta", venue_type: "โรงภาพยนตร์อินดี้" },
|
|
{ ...base, slug: "c-group", name: "Gamma", venue_type: "กลุ่มคนฉายหนัง" },
|
|
{ ...base, slug: "d-none", name: "Delta" },
|
|
];
|
|
|
|
it("กรอง all / unset / แต่ละประเภท", () => {
|
|
expect(filterAdminCinemas(list, { venue: "all", query: "" })).toHaveLength(
|
|
4,
|
|
);
|
|
expect(
|
|
filterAdminCinemas(list, { venue: "unset", query: "" }).map(
|
|
(c) => c.slug,
|
|
),
|
|
).toEqual(["d-none"]);
|
|
expect(
|
|
filterAdminCinemas(list, { venue: "โรงภาพยนตร์อินดี้", query: "" }).map(
|
|
(c) => c.slug,
|
|
),
|
|
).toEqual(["b-indie"]);
|
|
});
|
|
|
|
it("ค้นด้วยชื่อไทย/อังกฤษ/slug ร่วมกับตัวกรอง", () => {
|
|
expect(
|
|
filterAdminCinemas(list, { venue: "all", query: "อัลฟา" }).map(
|
|
(c) => c.slug,
|
|
),
|
|
).toEqual(["a-local"]);
|
|
expect(
|
|
filterAdminCinemas(list, { venue: "โรงภาพยนตร์ท้องถิ่น", query: "beta" }),
|
|
).toHaveLength(0);
|
|
expect(
|
|
filterAdminCinemas(list, { venue: "all", query: " GAMMA " })[0]?.slug,
|
|
).toBe("c-group");
|
|
});
|
|
|
|
it("setVenueForSlugs ตั้งค่าเฉพาะ slug ที่ระบุ และไม่แก้ตัวเดิม", () => {
|
|
const next = setVenueForSlugs(list, ["d-none", "b-indie"], "กลุ่มคนฉายหนัง");
|
|
expect(next.find((c) => c.slug === "d-none")?.venue_type).toBe(
|
|
"กลุ่มคนฉายหนัง",
|
|
);
|
|
expect(next.find((c) => c.slug === "b-indie")?.venue_type).toBe(
|
|
"กลุ่มคนฉายหนัง",
|
|
);
|
|
expect(next.find((c) => c.slug === "a-local")?.venue_type).toBe(
|
|
"โรงภาพยนตร์ท้องถิ่น",
|
|
);
|
|
expect(list.find((c) => c.slug === "d-none")?.venue_type).toBeUndefined();
|
|
expect(setVenueForSlugs(list, [], "โรงภาพยนตร์อินดี้")).toBe(list);
|
|
});
|
|
|
|
it("venueCounts นับครบทุกช่อง", () => {
|
|
expect(venueCounts(list)).toEqual({
|
|
all: 4,
|
|
unset: 1,
|
|
โรงภาพยนตร์ท้องถิ่น: 1,
|
|
โรงภาพยนตร์อินดี้: 1,
|
|
กลุ่มคนฉายหนัง: 1,
|
|
});
|
|
});
|
|
});
|