reboot alterflixhub
This commit is contained in:
commit
1e84023a44
188 files changed
+31629
No files matched your search
@@ -0,0 +1,100 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { Cinema } from "@/lib/cinemas";
|
||||
import { coordinatesQuery, mapEmbedUrl, mapOpenUrl, mapQueryFromUrl } from "@/lib/map-embed";
|
||||
|
||||
/**
|
||||
* สเปกของแผนที่หน้าโรงหนัง — ลำดับ fallback ตามที่ตกลง:
|
||||
* map_url → coordinates → "ไม่มีข้อมูล"
|
||||
*/
|
||||
|
||||
function cinema(patch: Partial<Cinema> = {}): Cinema {
|
||||
return {
|
||||
slug: "demo",
|
||||
name: "DEMO",
|
||||
tags: [],
|
||||
location_label: "",
|
||||
coordinates: null,
|
||||
description: "",
|
||||
map_url: null,
|
||||
address_lines: [],
|
||||
transport: [],
|
||||
contacts: [],
|
||||
payments: [],
|
||||
photos: [],
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
|
||||
describe("mapQueryFromUrl", () => {
|
||||
it("ดึงค่า q จากลิงก์ Google Maps", () => {
|
||||
expect(mapQueryFromUrl("https://maps.google.com/?q=House+Samyan")).toBe("House Samyan");
|
||||
expect(mapQueryFromUrl("https://www.google.com/maps?query=Mecani")).toBe("Mecani");
|
||||
});
|
||||
|
||||
it("ดึงพิกัดจาก /@lat,lng", () => {
|
||||
expect(
|
||||
mapQueryFromUrl("https://www.google.com/maps/place/X/@13.7466,100.5347,17z"),
|
||||
).toBe("13.7466,100.5347");
|
||||
});
|
||||
|
||||
it("ลิงก์ย่อแกะไม่ได้ → null (ให้ไปใช้พิกัดในหลังบ้าน)", () => {
|
||||
expect(mapQueryFromUrl("https://maps.app.goo.gl/abc123")).toBeNull();
|
||||
expect(mapQueryFromUrl("https://goo.gl/maps/xyz")).toBeNull();
|
||||
});
|
||||
|
||||
it("เว็บที่ไม่ใช่แผนที่ → null", () => {
|
||||
expect(mapQueryFromUrl("https://www.ilovemvp.com/")).toBeNull();
|
||||
expect(mapQueryFromUrl(null)).toBeNull();
|
||||
expect(mapQueryFromUrl(" ")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("coordinatesQuery", () => {
|
||||
it("คืน lat,lng เมื่อกรอกจริง", () => {
|
||||
expect(
|
||||
coordinatesQuery({ coordinates: { latitude: 13.7466, longitude: 100.5347 } }),
|
||||
).toBe("13.7466,100.5347");
|
||||
});
|
||||
|
||||
it("0,0 ถือว่ายังไม่กรอก", () => {
|
||||
expect(coordinatesQuery({ coordinates: { latitude: 0, longitude: 0 } })).toBeNull();
|
||||
expect(coordinatesQuery({ coordinates: null })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("mapEmbedUrl", () => {
|
||||
it("ใช้ map_url ก่อนพิกัด", () => {
|
||||
const url = mapEmbedUrl(
|
||||
cinema({
|
||||
map_url: "https://maps.google.com/?q=Doc+Club",
|
||||
coordinates: { latitude: 13.7, longitude: 100.5 },
|
||||
}),
|
||||
);
|
||||
expect(url).toContain("q=Doc%20Club");
|
||||
expect(url).toContain("output=embed");
|
||||
});
|
||||
|
||||
it("ไม่มี map_url → ใช้พิกัด", () => {
|
||||
const url = mapEmbedUrl(cinema({ coordinates: { latitude: 15.11, longitude: 104.32 } }));
|
||||
expect(url).toContain("q=15.11%2C104.32");
|
||||
});
|
||||
|
||||
it("ไม่มีทั้งคู่ → null (UI แสดง 'ไม่มีข้อมูล')", () => {
|
||||
expect(mapEmbedUrl(cinema())).toBeNull();
|
||||
});
|
||||
|
||||
it("ส่ง hl ตามภาษา", () => {
|
||||
const url = mapEmbedUrl(cinema({ coordinates: { latitude: 1, longitude: 2 } }), "en");
|
||||
expect(url).toContain("hl=en");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mapOpenUrl", () => {
|
||||
it("คืนลิงก์เปิดแผนที่ หรือ null", () => {
|
||||
expect(mapOpenUrl(cinema({ coordinates: { latitude: 1, longitude: 2 } }))).toContain(
|
||||
"maps.google.com/?q=1%2C2",
|
||||
);
|
||||
expect(mapOpenUrl(cinema())).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user