feat: บทความ 2 หน้า + แชร์/ลิงก์ย่อ + PWA + แอนิเมชัน + SEO/AI + เอกสาร
- บทความจากหลังบ้าน: /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 ไฟล์)
This commit is contained in:
1 parent
1e84023a44
commit
319c271d23
72 files changed
+4731
-765
No files matched your search
@@ -0,0 +1,99 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
countImages,
|
||||
createImageBlock,
|
||||
createParagraphBlock,
|
||||
moveBlock,
|
||||
removeBlock,
|
||||
sanitizeArticleBlocks,
|
||||
} from "./article";
|
||||
|
||||
describe("sanitizeArticleBlocks", () => {
|
||||
it("ไม่ใช่ array → คืนอาร์เรย์ว่าง", () => {
|
||||
expect(sanitizeArticleBlocks(undefined)).toEqual([]);
|
||||
expect(sanitizeArticleBlocks("ข้อความ")).toEqual([]);
|
||||
});
|
||||
|
||||
it("เก็บย่อหน้าที่มีข้อความ และตัดช่องว่างหัวท้าย", () => {
|
||||
expect(
|
||||
sanitizeArticleBlocks([{ type: "paragraph", text: " สวัสดี " }]),
|
||||
).toEqual([{ type: "paragraph", text: "สวัสดี" }]);
|
||||
});
|
||||
|
||||
it("ทิ้งย่อหน้าว่าง รูปที่ไม่มีลิงก์ และบล็อกชนิดที่ไม่รู้จัก", () => {
|
||||
expect(
|
||||
sanitizeArticleBlocks([
|
||||
{ type: "paragraph", text: " " },
|
||||
{ type: "image", src: " ", alt: "ไม่มีรูป" },
|
||||
{ type: "video", src: "x.mp4" },
|
||||
{ type: "paragraph", text: "เก็บอันนี้" },
|
||||
]),
|
||||
).toEqual([{ type: "paragraph", text: "เก็บอันนี้" }]);
|
||||
});
|
||||
|
||||
it("รูปเก็บ src/alt/caption และตัดฟิลด์เกินทิ้ง", () => {
|
||||
expect(
|
||||
sanitizeArticleBlocks([
|
||||
{
|
||||
type: "image",
|
||||
src: " /images/a.jpg ",
|
||||
alt: " บรรยากาศ ",
|
||||
caption: " โรงใหม่ ",
|
||||
evil: "x",
|
||||
},
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
type: "image",
|
||||
src: "/images/a.jpg",
|
||||
alt: "บรรยากาศ",
|
||||
caption: "โรงใหม่",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("คงลำดับบล็อกตามที่รับมา", () => {
|
||||
const blocks = sanitizeArticleBlocks([
|
||||
{ type: "paragraph", text: "หนึ่ง" },
|
||||
{ type: "image", src: "/a.jpg" },
|
||||
{ type: "paragraph", text: "สอง" },
|
||||
]);
|
||||
expect(blocks.map((block) => block.type)).toEqual([
|
||||
"paragraph",
|
||||
"image",
|
||||
"paragraph",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("moveBlock / removeBlock", () => {
|
||||
const blocks = [
|
||||
createParagraphBlock("หนึ่ง"),
|
||||
createParagraphBlock("สอง"),
|
||||
createImageBlock(),
|
||||
];
|
||||
|
||||
it("เลื่อนขึ้น/ลงสลับตำแหน่งถูกต้อง", () => {
|
||||
expect(
|
||||
moveBlock(blocks, 1, -1).map((b) =>
|
||||
b.type === "paragraph" ? b.text : "img",
|
||||
),
|
||||
).toEqual(["สอง", "หนึ่ง", "img"]);
|
||||
expect(moveBlock(blocks, 0, 1)[1]).toEqual(blocks[0]);
|
||||
});
|
||||
|
||||
it("ไม่ทำอะไรเมื่อเกินขอบ", () => {
|
||||
expect(moveBlock(blocks, 0, -1)).toEqual(blocks);
|
||||
expect(moveBlock(blocks, blocks.length - 1, 1)).toEqual(blocks);
|
||||
});
|
||||
|
||||
it("ลบบล็อกตามตำแหน่ง และไม่แตะเมื่อ index ผิด", () => {
|
||||
expect(removeBlock(blocks, 1)).toHaveLength(2);
|
||||
expect(removeBlock(blocks, 99)).toHaveLength(3);
|
||||
});
|
||||
|
||||
it("นับจำนวนรูปได้", () => {
|
||||
expect(countImages(blocks)).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user