97 行
2.7 KiB
TypeScript
97 行
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
normalizeAdjustedPlanResponse,
|
|
normalizeTrainingPlanResponse,
|
|
} from "./trainingPlan";
|
|
|
|
describe("normalizeTrainingPlanResponse", () => {
|
|
it("accepts canonical title/exercises output", () => {
|
|
const result = normalizeTrainingPlanResponse({
|
|
content: JSON.stringify({
|
|
title: "7天训练计划",
|
|
exercises: [
|
|
{
|
|
day: 1,
|
|
name: "正手影子挥拍",
|
|
category: "影子挥拍",
|
|
duration: 15,
|
|
description: "完成正手挥拍练习",
|
|
tips: "保持重心稳定",
|
|
sets: 3,
|
|
reps: 12,
|
|
},
|
|
],
|
|
}),
|
|
fallbackTitle: "fallback",
|
|
});
|
|
|
|
expect(result.title).toBe("7天训练计划");
|
|
expect(result.exercises).toHaveLength(1);
|
|
expect(result.exercises[0]?.category).toBe("影子挥拍");
|
|
});
|
|
|
|
it("normalizes qwen day map output into plan exercises", () => {
|
|
const result = normalizeTrainingPlanResponse({
|
|
content: JSON.stringify({
|
|
day_1: {
|
|
duration_minutes: 45,
|
|
focus: "基础握拍与正手影子挥拍",
|
|
exercises: [
|
|
{
|
|
name: "握拍方式学习",
|
|
description: "学习大陆式与东方式握拍",
|
|
duration_minutes: 10,
|
|
},
|
|
{
|
|
name: "原地小碎步热身与放松",
|
|
description: "30秒快速小碎步 + 30秒休息",
|
|
duration_minutes: 10,
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
fallbackTitle: "7天训练计划",
|
|
});
|
|
|
|
expect(result.title).toBe("7天训练计划");
|
|
expect(result.exercises).toHaveLength(2);
|
|
expect(result.exercises[0]).toMatchObject({
|
|
day: 1,
|
|
name: "握拍方式学习",
|
|
duration: 10,
|
|
sets: 3,
|
|
reps: 10,
|
|
});
|
|
expect(result.exercises[1]?.category).toBe("脚步移动");
|
|
});
|
|
});
|
|
|
|
describe("normalizeAdjustedPlanResponse", () => {
|
|
it("fills missing adjustment notes for day map output", () => {
|
|
const result = normalizeAdjustedPlanResponse({
|
|
content: JSON.stringify({
|
|
day_1: {
|
|
duration_minutes: 30,
|
|
focus: "脚步移动",
|
|
exercises: [
|
|
{
|
|
name: "交叉步移动",
|
|
description: "左右移动并快速回位",
|
|
duration_minutes: 12,
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
fallbackTitle: "当前训练计划",
|
|
});
|
|
|
|
expect(result.title).toBe("当前训练计划");
|
|
expect(result.adjustmentNotes).toContain("已根据最近分析结果调整");
|
|
expect(result.exercises[0]).toMatchObject({
|
|
day: 1,
|
|
name: "交叉步移动",
|
|
category: "脚步移动",
|
|
});
|
|
});
|
|
});
|