Files
WonderQ-Project/WonderQ-MiniAPP/tests/data.test.ts
duanshuwen d42f69bd47 feat: 新增用车需求服务及线索管理全功能
- 新增后台用车服务配置模块,支持维护服务简介、优势与使用流程
- 新增需求线索管理页面,支持筛选、查看与更新用车线索状态
- 新增小程序用车需求页面,优化登录路径与回跳逻辑
- 优化车型卡片跳转与用车需求提交功能
- 新增服务端API与数据处理逻辑,完善权限校验
- 更新全站配置与API文档,新增相关测试用例
2026-08-22 21:48:08 +08:00

82 lines
2.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { fallbackData, getSubmitErrorMessage, normalizeSiteConfig } from "@/lib/data";
import type { PublicSiteConfig } from "@/lib/types";
describe("WonderQ shared data helpers", () => {
it("uses local defaults when the site configuration is empty", () => {
expect(normalizeSiteConfig({}, fallbackData)).toEqual(fallbackData);
});
it("normalizes active site modules and ignores incomplete records", () => {
const config: PublicSiteConfig = {
destinationHero: [
{
id: "hero-1",
title: "后台主视觉标题",
kicker: "后台小标题",
image: "https://cdn.example.test/hero.jpg",
isActive: true,
sortOrder: 0,
},
],
demandForm: [
{
id: "form-1",
destinationLabel: "想去哪里",
submitLabel: "提交给管家",
chips: [" 贵州 ", "", "黄果树"],
isActive: true,
},
],
};
const data = normalizeSiteConfig(config, fallbackData);
expect(data.destinationHero).toMatchObject({
id: "hero-1",
title: "后台主视觉标题",
image: "https://cdn.example.test/hero.jpg",
});
expect(data.demandForm).toMatchObject({
id: "form-1",
destinationLabel: "想去哪里",
submitLabel: "提交给管家",
chips: ["贵州", "黄果树"],
});
});
it("returns a stable submit error message", () => {
expect(getSubmitErrorMessage(new Error("网络异常"))).toBe("网络异常");
expect(getSubmitErrorMessage("unknown")).toBe("提交失败,请稍后再试。");
});
it("normalizes the vehicle service module and falls back incomplete sections", () => {
const config: PublicSiteConfig = {
vehicleService: {
id: "vehicle-service-1",
introTitle: "旅游专属用车",
intro: " 提交需求后由管家跟进。 ",
serviceSections: [{ title: " 包车服务 ", description: " 灵活安排 " }],
advantages: [" 车型齐全 ", ""],
processSteps: [{ title: "提交需求", description: " 填写出行信息 " }],
isActive: true,
},
};
const data = normalizeSiteConfig(config, fallbackData);
expect(data.vehicleService).toMatchObject({
id: "vehicle-service-1",
introTitle: "旅游专属用车",
intro: "提交需求后由管家跟进。",
advantages: ["车型齐全"],
});
expect(data.vehicleService.serviceSections).toEqual([
{ title: "包车服务", description: "灵活安排" },
]);
expect(data.vehicleService.processSteps).toEqual([
{ title: "提交需求", description: "填写出行信息" },
]);
});
});