import { describe, expect, it } from "vitest"; import { normalizePlayCategories } from "@/pages/play/components/playTypes"; describe("normalizePlayCategories", () => { it("normalizes the public response and ignores incomplete categories or routes", () => { expect( normalizePlayCategories({ categories: [ { id: "family-route", label: " 亲子路线 ", routes: [ { id: "family-water", title: " 亲子玩水 ", subtitle: "贵州·轻松节奏与自然课堂", image: "https://example.test/family-water.jpg", routeCount: 4, demandKeyword: "亲子玩水", }, { id: "incomplete-route", title: "缺少图片" }, ], }, { id: "incomplete-category", label: "没有路线", routes: [] }, { id: "missing-label", routes: [{ id: "route", title: "无效" }] }, ], }), ).toEqual([ { id: "family-route", label: "亲子路线", routes: [ { id: "family-water", title: "亲子玩水", subtitle: "贵州·轻松节奏与自然课堂", image: "https://example.test/family-water.jpg", routeCount: 4, demandKeyword: "亲子玩水", }, ], }, ]); }); it("returns an empty list for an invalid public response", () => { expect(normalizePlayCategories({ categories: null })).toEqual([]); expect(normalizePlayCategories(null)).toEqual([]); }); });