- 为后端Admin新增migration_compat工具,支持离线迁移时的基线资源检查,重构全部alembic迁移脚本适配离线模式,避免重复创建已存在的数据库表和字段 - 完善初始数据库迁移脚本,添加默认部门种子数据,新增ConciergeAdvisor详情字段从JSON到JSONB的类型转换迁移 - 小程序端新增图片资源解析工具resolveNetworkImage,实现本地静态资源到CDN的自动映射,添加图片加载容错降级机制 - 完善HeroSlide类型定义,新增actionLabel字段,优化首页轮播组件的文本渲染与错误处理逻辑 - 新增对应测试用例验证迁移路径正确性与前端数据处理逻辑 - 新增临时 brainstorm UI对比草稿与开发临时状态文件
114 lines
3.4 KiB
TypeScript
114 lines
3.4 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 the supported home modules and keeps the local vehicle fallback", () => {
|
|
const config: PublicSiteConfig = {
|
|
heroSlides: [
|
|
{
|
|
id: "hero-1",
|
|
title: "后台首页主视觉",
|
|
kicker: "后台小标题",
|
|
image: "https://cdn.example.test/hero.jpg",
|
|
isActive: true,
|
|
sortOrder: 0,
|
|
},
|
|
],
|
|
vehicleOptions: [
|
|
{
|
|
id: "vehicle-1",
|
|
title: "舒适型用车",
|
|
description: "适合家庭出行",
|
|
image: "https://cdn.example.test/vehicle.jpg",
|
|
isActive: true,
|
|
sortOrder: 0,
|
|
},
|
|
],
|
|
};
|
|
|
|
const data = normalizeSiteConfig(config, fallbackData);
|
|
|
|
expect(data.heroSlides).toMatchObject([
|
|
{
|
|
id: "hero-1",
|
|
title: "后台首页主视觉",
|
|
image: "https://cdn.example.test/hero.jpg",
|
|
},
|
|
]);
|
|
expect(data.vehicleOptions).toMatchObject([
|
|
{
|
|
id: "vehicle-1",
|
|
title: "舒适型用车",
|
|
description: "适合家庭出行",
|
|
},
|
|
]);
|
|
expect(data.vehicleService.introTitle).toBe("旅游出行专属用车服务");
|
|
});
|
|
|
|
it("keeps the backend hero actionLabel when normalizing site config", () => {
|
|
const config: PublicSiteConfig = {
|
|
heroSlides: [
|
|
{
|
|
id: "hero-api",
|
|
title: "经典人文打卡线路",
|
|
kicker: "经典人文",
|
|
actionLabel: "查看线路",
|
|
image: "https://cdn.example.test/hero.webp",
|
|
targetType: null,
|
|
targetValue: null,
|
|
},
|
|
],
|
|
};
|
|
|
|
const data = normalizeSiteConfig(config, fallbackData);
|
|
|
|
expect(data.heroSlides[0]).toMatchObject({
|
|
id: "hero-api",
|
|
title: "经典人文打卡线路",
|
|
kicker: "经典人文",
|
|
actionLabel: "查看线路",
|
|
image: "https://cdn.example.test/hero.webp",
|
|
});
|
|
});
|
|
|
|
it("replaces root-relative API images with network fallbacks", () => {
|
|
const config: PublicSiteConfig = {
|
|
heroSlides: [
|
|
{
|
|
id: "hero-local-path",
|
|
title: "山野户外",
|
|
image: "/assets/guizhou/wanfenglin.jpg",
|
|
},
|
|
],
|
|
vehicleOptions: [
|
|
{
|
|
id: "vehicle-local-path",
|
|
title: "舒适型用车",
|
|
description: "适合家庭出行",
|
|
image: "/assets/guizhou/jiaxiu-tower.jpg",
|
|
},
|
|
],
|
|
};
|
|
|
|
const data = normalizeSiteConfig(config, fallbackData);
|
|
|
|
expect(data.heroSlides[0]?.image).toBe(
|
|
"https://wanfenglin-guanwang.oss-cn-chengdu.aliyuncs.com/uploads/20240718/23ea4291a9570b94a1f8df9a012c18ec.jpg",
|
|
);
|
|
expect(data.vehicleOptions[0]?.image).toBe(
|
|
"https://dimg04.c-ctrip.com/images/1me6m12000rntioi4FFB2.jpg?proc=source%2Ftripcommunity",
|
|
);
|
|
});
|
|
|
|
it("returns a stable submit error message", () => {
|
|
expect(getSubmitErrorMessage(new Error("网络异常"))).toBe("网络异常");
|
|
expect(getSubmitErrorMessage("unknown")).toBe("提交失败,请稍后再试。");
|
|
});
|
|
|
|
});
|