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,90 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import {
|
||||
buildShareUrl,
|
||||
buildShortSharePath,
|
||||
resolveShareOrigin,
|
||||
shareOrCopy,
|
||||
} from "./share";
|
||||
|
||||
describe("buildShareUrl", () => {
|
||||
it("ต่อ origin กับ path และตัด / ซ้ำท้าย origin", () => {
|
||||
expect(buildShareUrl("https://alterflixhub.com/", "/cinema/lido")).toBe(
|
||||
"https://alterflixhub.com/cinema/lido",
|
||||
);
|
||||
expect(buildShareUrl("http://localhost:8080", "cinema/lido")).toBe(
|
||||
"http://localhost:8080/cinema/lido",
|
||||
);
|
||||
});
|
||||
|
||||
it("คงพาธที่มีภาษาไทยไว้ตามเดิม", () => {
|
||||
expect(buildShareUrl("https://x.test", "/cinema/เมืองทองรามา")).toBe(
|
||||
"https://x.test/cinema/เมืองทองรามา",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveShareOrigin", () => {
|
||||
it("ใช้โดเมนที่ตั้งไว้ และตัด / ท้ายออก", () => {
|
||||
expect(
|
||||
resolveShareOrigin(
|
||||
"https://alterflixhub.hobbypj.com/",
|
||||
"http://localhost:8080",
|
||||
),
|
||||
).toBe("https://alterflixhub.hobbypj.com");
|
||||
});
|
||||
|
||||
it("ไม่ได้ตั้ง (ว่าง/undefined) → ใช้ origin ของหน้าเว็บ", () => {
|
||||
expect(resolveShareOrigin("", "http://localhost:8080")).toBe(
|
||||
"http://localhost:8080",
|
||||
);
|
||||
expect(resolveShareOrigin(undefined, "http://localhost:8080")).toBe(
|
||||
"http://localhost:8080",
|
||||
);
|
||||
expect(resolveShareOrigin(" ", "http://localhost:8080")).toBe(
|
||||
"http://localhost:8080",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildShortSharePath", () => {
|
||||
it("สร้างลิงก์ย่อ /c/<slug>", () => {
|
||||
expect(buildShortSharePath("kku-cinema")).toBe("/c/kku-cinema");
|
||||
});
|
||||
});
|
||||
|
||||
describe("shareOrCopy", () => {
|
||||
const data = { title: "LIDO CONNECT", url: "https://x.test/cinema/lido" };
|
||||
|
||||
it("มี navigator.share → เรียกแผงแชร์ แล้วคัดลอกสำรองด้วย คืน shared", async () => {
|
||||
const share = vi.fn().mockResolvedValue(undefined);
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
expect(await shareOrCopy(data, { share, writeText })).toBe("shared");
|
||||
expect(share).toHaveBeenCalledWith({ title: data.title, url: data.url });
|
||||
expect(writeText).toHaveBeenCalledWith(data.url);
|
||||
});
|
||||
|
||||
it("ไม่มี navigator.share → คัดลอกแล้วคืน copied", async () => {
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
expect(await shareOrCopy(data, { writeText })).toBe("copied");
|
||||
expect(writeText).toHaveBeenCalledWith(data.url);
|
||||
});
|
||||
|
||||
it("ผู้ใช้ยกเลิกแผงแชร์ แต่คัดลอกได้ → ยังคืน shared", async () => {
|
||||
const share = vi.fn().mockRejectedValue(new Error("AbortError"));
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
expect(await shareOrCopy(data, { share, writeText })).toBe("shared");
|
||||
});
|
||||
|
||||
it("clipboard ใช้ไม่ได้ → ตกไปใช้ legacyCopy", async () => {
|
||||
const writeText = vi.fn().mockRejectedValue(new Error("denied"));
|
||||
const legacyCopy = vi.fn().mockReturnValue(true);
|
||||
expect(await shareOrCopy(data, { writeText, legacyCopy })).toBe("copied");
|
||||
expect(legacyCopy).toHaveBeenCalledWith(data.url);
|
||||
});
|
||||
|
||||
it("ทุกทางล้มเหลว → failed", async () => {
|
||||
expect(await shareOrCopy(data, {})).toBe("failed");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user