feat: add progress display helpers

This commit is contained in:
Codex
2026-06-21 23:43:03 +08:00
parent 933ac94edf
commit 60cf55f755
2 changed files with 77 additions and 0 deletions
@@ -0,0 +1,36 @@
import { describe, expect, it } from "vitest";
import {
formatElapsedSeconds,
getElapsedNotice,
getProgressStages,
} from "../progress";
describe("progress helpers", () => {
it("formats elapsed seconds as short Chinese text", () => {
expect(formatElapsedSeconds(0)).toBe("0 秒");
expect(formatElapsedSeconds(39)).toBe("39 秒");
expect(formatElapsedSeconds(65)).toBe("1 分 5 秒");
});
it("uses a neutral 10-40 second expectation without naming a model", () => {
expect(getElapsedNotice(5)).toBe("通常需要 10-40 秒,请保持页面打开。");
expect(getElapsedNotice(45)).toBe("仍在处理中,请保持页面打开。");
expect(getElapsedNotice(75)).toBe("耗时较长,仍在等待服务返回。");
expect(getElapsedNotice(5)).not.toMatch(/DeepSeek|OpenAI|模型|model/i);
});
it("returns stage labels for analyze and optimize actions", () => {
expect(getProgressStages("analyze").map((stage) => stage.label)).toEqual([
"读取文章输入",
"提取事实卡",
"生成待确认信息",
]);
expect(getProgressStages("optimize").map((stage) => stage.label)).toEqual([
"生成优化稿",
"质量检查",
"必要时定向修复",
"整理结果",
]);
});
});
+41
View File
@@ -0,0 +1,41 @@
export type ProgressAction = "analyze" | "confirm" | "optimize";
export interface ProgressStage {
label: string;
}
const progressStages: Record<ProgressAction, ProgressStage[]> = {
analyze: [
{ label: "读取文章输入" },
{ label: "提取事实卡" },
{ label: "生成待确认信息" },
],
confirm: [
{ label: "校验事实卡" },
{ label: "保存品牌事实" },
],
optimize: [
{ label: "生成优化稿" },
{ label: "质量检查" },
{ label: "必要时定向修复" },
{ label: "整理结果" },
],
};
export function formatElapsedSeconds(seconds: number) {
const safeSeconds = Math.max(0, Math.floor(seconds));
if (safeSeconds < 60) return `${safeSeconds}`;
const minutes = Math.floor(safeSeconds / 60);
const remainingSeconds = safeSeconds % 60;
return `${minutes}${remainingSeconds}`;
}
export function getElapsedNotice(seconds: number) {
if (seconds >= 60) return "耗时较长,仍在等待服务返回。";
if (seconds >= 40) return "仍在处理中,请保持页面打开。";
return "通常需要 10-40 秒,请保持页面打开。";
}
export function getProgressStages(action: ProgressAction) {
return progressStages[action];
}