- บทความจากหลังบ้าน: /for-film-lovers, /for-cinemas (ArticlePage + ArticleEditor แบบบล็อกย่อหน้า/รูป) - แชร์: ปุ่มบนการ์ดและท้ายหน้ารายละเอียด · ลิงก์ย่อ /c/<slug> (302) · ธีมแก้วตาม DESIGN.md - PWA: manifest/sw/offline + ถอดการล็อกซูม (WCAG 1.4.4) + touch target ≥44px - แอนิเมชัน reveal: IntersectionObserver + gate ด้วย html.fx-motion · เคารพ prefers-reduced-motion - ค้นหา: normalize/ตัดวรรณยุกต์ + AND หลายคำ + จัดอันดับ · รองรับ /?q= จาก SearchAction - SEO: pageMeta (canonical/OG/Twitter) + JSON-LD (WebSite/Organization/BreadcrumbList/MovieTheater/Article) - ไม่ฝังโดเมนในโค้ด: origin มาจาก request (x-forwarded-host/proto) ทั้ง canonical, sitemap, robots, ลิงก์แชร์ - กัน AI: robots.txt (Nitro route, บล็อก AI 21 ตัว) + ai.txt + OG image 1200x630 - เอกสาร: README สรุปโปรเจกต์, DESIGN.md (motion/PWA/SEO/ข้อมูล), architecture.html, admin-guide - tests: 135 ผ่าน (16 ไฟล์)
89 lines
3.8 KiB
TypeScript
89 lines
3.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { seedForCinemas, seedForFilmLovers } from "./content-seed";
|
|
import { sanitizeForCinemas, sanitizeForFilmLovers } from "./content.server";
|
|
|
|
/**
|
|
* ทดสอบตัวตรวจข้อมูลของหน้าบทความทั้งสองหน้า
|
|
* (สำหรับคนทำโรงหนัง / สำหรับคนรักหนัง)
|
|
* ค่าที่เว้นว่าง/ผิดรูปแบบต้องถูกแทนด้วยค่าเริ่มต้น ไม่ใช่ปล่อยให้หน้าเว็บว่าง
|
|
*/
|
|
describe("sanitizeForCinemas", () => {
|
|
const seed = seedForCinemas();
|
|
|
|
it("ไม่ส่งข้อมูลมา → คืนค่าเริ่มต้นทั้งสองภาษา", () => {
|
|
expect(sanitizeForCinemas(undefined)).toEqual(seed);
|
|
expect(sanitizeForCinemas("ผิดรูปแบบ")).toEqual(seed);
|
|
});
|
|
|
|
it("เก็บบล็อกที่ถูกต้องตามลำดับ และตัดบล็อกที่ว่าง", () => {
|
|
const result = sanitizeForCinemas({
|
|
th: {
|
|
title: "สำหรับคนทำโรงหนัง",
|
|
lead: "เกริ่น",
|
|
blocks: [
|
|
{ type: "paragraph", text: "หนึ่ง" },
|
|
{ type: "paragraph", text: " " },
|
|
{ type: "image", src: "/images/a.jpg", alt: "a", caption: "" },
|
|
{ type: "image", src: "" },
|
|
],
|
|
contactHeading: "ติดต่อ",
|
|
contactNote: "โน้ต",
|
|
},
|
|
});
|
|
|
|
expect(result.th.blocks).toEqual([
|
|
{ type: "paragraph", text: "หนึ่ง" },
|
|
{ type: "image", src: "/images/a.jpg", alt: "a", caption: "" },
|
|
]);
|
|
expect(result.th.title).toBe("สำหรับคนทำโรงหนัง");
|
|
});
|
|
|
|
it("ฟิลด์ที่เว้นว่างถูกแทนด้วยค่าเริ่มต้น", () => {
|
|
const result = sanitizeForCinemas({
|
|
th: {
|
|
title: " ",
|
|
lead: "",
|
|
blocks: [],
|
|
contactHeading: "",
|
|
contactNote: "",
|
|
},
|
|
});
|
|
expect(result.th.title).toBe(seed.th.title);
|
|
expect(result.th.lead).toBe(seed.th.lead);
|
|
expect(result.th.blocks).toEqual(seed.th.blocks);
|
|
expect(result.th.contactHeading).toBe(seed.th.contactHeading);
|
|
expect(result.th.contactNote).toBe(seed.th.contactNote);
|
|
});
|
|
|
|
it("ภาษา en ที่ไม่ส่งมาจะได้ค่าเริ่มต้นของ en", () => {
|
|
const result = sanitizeForCinemas({ th: { title: "ไทยเท่านั้น" } });
|
|
expect(result.en).toEqual(seed.en);
|
|
});
|
|
});
|
|
|
|
describe("sanitizeForFilmLovers", () => {
|
|
const seed = seedForFilmLovers();
|
|
|
|
it("ไม่ส่งข้อมูลมา → ค่าเริ่มต้นของหน้า 'สำหรับคนรักหนัง'", () => {
|
|
expect(sanitizeForFilmLovers(undefined)).toEqual(seed);
|
|
expect(seed.th.title).not.toBe(seedForCinemas().th.title);
|
|
});
|
|
|
|
it("เก็บบล็อกและหัวเรื่องที่ส่งมา ตัดบล็อกว่าง", () => {
|
|
const result = sanitizeForFilmLovers({
|
|
th: {
|
|
title: "สำหรับคนรักหนัง",
|
|
blocks: [
|
|
{ type: "paragraph", text: "ย่อหน้า" },
|
|
{ type: "image", src: "/images/a.jpg", alt: "alt", caption: "" },
|
|
{ type: "paragraph", text: "" },
|
|
],
|
|
},
|
|
});
|
|
expect(result.th.blocks).toHaveLength(2);
|
|
expect(result.th.title).toBe("สำหรับคนรักหนัง");
|
|
expect(result.th.lead).toBe(seed.th.lead);
|
|
});
|
|
});
|