63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
DEFAULT_CATEGORY,
|
|
filterCinemas,
|
|
findCinemaBySlug,
|
|
listOtherCinemas,
|
|
CINEMAS,
|
|
} from "./cinemas";
|
|
|
|
describe("filterCinemas", () => {
|
|
it("คืนทุกโรงหนังเมื่อเลือกหมวดทั้งหมดและไม่พิมพ์ค้นหา", () => {
|
|
const result = filterCinemas(CINEMAS, { category: DEFAULT_CATEGORY, query: "" });
|
|
expect(result.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("กรองตามหมวดหมู่จาก tags", () => {
|
|
const result = filterCinemas(CINEMAS, { category: "อาร์ตเฮาส์", query: "" });
|
|
expect(result.length).toBeGreaterThan(0);
|
|
expect(result.every((cinema) => cinema.tags.includes("อาร์ตเฮาส์"))).toBe(
|
|
true,
|
|
);
|
|
});
|
|
|
|
it("ค้นหาแบบไม่สนตัวพิมพ์และตัดช่องว่างหัวท้าย", () => {
|
|
const result = filterCinemas(CINEMAS, {
|
|
category: DEFAULT_CATEGORY,
|
|
query: " house ",
|
|
});
|
|
expect(result.map((cinema) => cinema.slug)).toContain(
|
|
"house-cinema-samyan",
|
|
);
|
|
});
|
|
|
|
it("คืนอาร์เรย์ว่างเมื่อไม่พบคำค้น", () => {
|
|
expect(
|
|
filterCinemas(CINEMAS, { category: DEFAULT_CATEGORY, query: "ไม่มีโรงนี้แน่นอน" }),
|
|
).toEqual([]);
|
|
});
|
|
});
|
|
|
|
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",
|
|
);
|
|
});
|
|
});
|