feat(admin): รองรับตัวกรองประเภทโรงหนังเต็มรูปแบบ
- ลิสต์โรงหนัง: ช่องค้นหา (ไทย/อังกฤษ/slug) + ชิปกรองประเภทพร้อมจำนวน (ทั้งหมด/ท้องถิ่น/อินดี้/กลุ่ม/ยังไม่จัด) - ป้ายประเภทท้ายชื่อทุกแถว (ยังไม่จัด = ป้ายแดง) + empty state - ตั้งประเภททีละกลุ่ม: "ตั้งประเภทให้ N โรงที่กรองอยู่" → เลือกประเภท → ใช้ (แล้วกดบันทึกทั้งหมด) - หัวหลังบ้านสรุปจำนวนต่อประเภท - แท็บคำศัพท์: ปุ่มลัดสร้าง key `venues.<ประเภท>` สำหรับแปลชื่อตัวกรอง - ปิดลากสลับลำดับขณะกรอง + hint อธิบาย - logic ย้ายไป lib: filterAdminCinemas / setVenueForSlugs / venueCounts + unit tests (169 ผ่าน) - DESIGN.md / docs/admin-guide.md อัปเดต
This commit is contained in:
1 parent
1932098a1d
commit
1cf1398ba4
6 files changed
+377
-16
No files matched your search
@@ -6,6 +6,9 @@ import {
|
||||
hasVenue,
|
||||
listOtherCinemas,
|
||||
type Cinema,
|
||||
filterAdminCinemas,
|
||||
setVenueForSlugs,
|
||||
venueCounts,
|
||||
} from "./cinemas";
|
||||
import { filterCinemas } from "./search";
|
||||
|
||||
@@ -98,3 +101,87 @@ describe("hasVenue / filterCinemas (ชั้นกรองประเภท
|
||||
).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,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user