import { describe, expect, it } from "vitest"; import { findWanfaRouteDetailFallback, normalizeDetailPresentation, } from "@/pages/detail/components/detailPresentation"; describe("wanfa route detail presentation", () => { it("normalizes a complete public response", () => { expect( normalizeDetailPresentation({ key: "family-water", eyebrow: " 玩法推荐 ", duration: " 5天4晚 ", title: " 亲子玩水 ", subtitle: " 贵州路线 ", intro: " 沿着山地深入探索。 ", highlights: [" 核心景观串联 ", "", " 小团出行 "], included: [" 行程内用车 "], excluded: [" 往返大交通 "], notes: [" 请准备雨具。 "], gallery: [" https://example.test/cover.jpg "], priceStartingValue: 1.68, priceUnit: "person", pricePeopleRange: " 2-4人 ", priceDescription: " 价格以最终确认方案为准。 ", conciergeAdvisor: null, }), ).toEqual({ key: "family-water", eyebrow: "玩法推荐", duration: "5天4晚", title: "亲子玩水", subtitle: "贵州路线", intro: "沿着山地深入探索。", highlights: ["核心景观串联", "小团出行"], included: ["行程内用车"], excluded: ["往返大交通"], notes: ["请准备雨具。"], gallery: ["https://example.test/cover.jpg"], priceStartingValue: 1.68, priceUnit: "person", pricePeopleRange: "2-4人", priceDescription: "价格以最终确认方案为准。", conciergeAdvisor: null, }); }); it("normalizes a valid concierge advisor without inventing fallback data", () => { expect( normalizeDetailPresentation({ key: "family-water", eyebrow: "玩法推荐", duration: "5天4晚", title: "亲子玩水", subtitle: "贵州路线", intro: "介绍", highlights: [], included: [], excluded: [], notes: [], gallery: ["https://example.test/cover.jpg"], conciergeAdvisor: { avatar: " https://example.test/amanda.jpg ", name: " Amanda ", role: " SENIOR TRAVEL ADVISOR ", details: [{ icon: " calendar ", label: " 服务经验:8年 " }], qrImage: " https://example.test/amanda-qr.png ", }, }), ).toMatchObject({ conciergeAdvisor: { avatar: "https://example.test/amanda.jpg", name: "Amanda", role: "SENIOR TRAVEL ADVISOR", details: [{ icon: "calendar", label: "服务经验:8年" }], qrImage: "https://example.test/amanda-qr.png", }, }); }); it("uses the route fallback for invalid or incomplete API data", () => { const fallback = findWanfaRouteDetailFallback("family-water"); expect(fallback).not.toBeNull(); expect( normalizeDetailPresentation( { key: "family-water", title: "", gallery: [] }, fallback, ), ).toEqual(fallback); }); it("returns no fallback for an unknown route", () => { expect(findWanfaRouteDetailFallback("missing-route")).toBeNull(); }); });