Skip to content

Commit ee5db04

Browse files
committed
fix COD-46:补失败趋势错误文案英文并加告警/上游概况英文回归
1 parent db9ef31 commit ee5db04

3 files changed

Lines changed: 85 additions & 3 deletions

File tree

‎web/src/api/statsErrors.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async function fetchStatsErrorTrend(
127127
},
128128
);
129129
if (!response.ok) {
130-
throw new Error(`失败趋势加载失败(HTTP ${response.status})`);
130+
throw new Error(tr("失败趋势加载失败(HTTP {0})", [response.status]));
131131
}
132132
return (await response.json()) as StatsErrorTrendResponse;
133133
}

‎web/src/i18n/text.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ export const TEXT_EN: Record<string, string> = {
10241024
"天失败": "days failed",
10251025
"天)·": "days) ·",
10261026
"失败归因加载失败(HTTP {0})": "Failed to load failure attribution (HTTP {0})",
1027+
"失败趋势加载失败(HTTP {0})": "Failed to load failure trend (HTTP {0})",
10271028
"完成": "Done",
10281029
"官方状态页": "Official status pages",
10291030
"官方状态页粒度比本服务的模型级冷却粗、更新也滞后,这里只做解释,不参与选号 / 熔断;本服务实时冷却见「凭证管理」页。数据仅存内存,服务重启后归零。": "Official status pages are coarser than this service's per-model cooldown and lag behind, so they only explain, they never pick credentials or trip the breaker; see the credentials page for live cooldowns. The data lives in memory only and resets when the service restarts.",
@@ -1278,8 +1279,6 @@ export const TEXT_EN: Record<string, string> = {
12781279
"运行中…": "Running…",
12791280
"运行时配置加载失败": "Failed to load runtime settings",
12801281
"近": "Last ",
1281-
"近 30 天": "Last 30 days",
1282-
"近 7 天": "Last 7 days",
12831282
"近期事故": "Recent incidents",
12841283
"返回": "Back",
12851284
"还没有备份": "No backups yet",
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { screen, waitFor, within } from "@testing-library/react";
2+
import { beforeEach, describe, expect, it, vi } from "vitest";
3+
import { I18nProvider } from "@/i18n";
4+
import { PoolOverview } from "@/components/PoolOverview";
5+
import type { Credential } from "@/api/types";
6+
import { makeCredential, renderPage } from "@/test-utils";
7+
import { AlertsPage } from "../AlertsPage";
8+
9+
const CJK = /[\u4e00-\u9fff]/;
10+
11+
/** 英文态渲染页面(Layout 提供会话与导航,Provider 决定语言)。 */
12+
function renderEn(ui: React.ReactNode) {
13+
return renderPage(<I18nProvider initial="en">{ui}</I18nProvider>, {
14+
username: "root",
15+
is_admin: true,
16+
});
17+
}
18+
19+
function stubFetch(body: unknown) {
20+
const spy = vi.fn(
21+
async () =>
22+
new Response(JSON.stringify(body), {
23+
status: 200,
24+
headers: { "Content-Type": "application/json" },
25+
}),
26+
);
27+
vi.stubGlobal("fetch", spy);
28+
return spy;
29+
}
30+
31+
describe("告警页 / 上游概况:英文态插值文案不再漏中文", () => {
32+
beforeEach(() => {
33+
vi.unstubAllGlobals();
34+
});
35+
36+
it("告警页标题与记录 aria-label 均为英文(含条数插值)", async () => {
37+
stubFetch({
38+
total: 1,
39+
alerts: [
40+
{
41+
id: "alert_1",
42+
ts: 1_700_000_000,
43+
rule: "pool_empty",
44+
severity: "critical",
45+
scope: "pool",
46+
message: "No credentials available",
47+
detail: "{}",
48+
delivered: 1,
49+
delivery_error: null,
50+
resolved_at: null,
51+
},
52+
],
53+
});
54+
renderEn(<AlertsPage />);
55+
const main = await screen.findByRole("main");
56+
await waitFor(
57+
() => expect(within(main).getByTestId("alerts-table")).toBeInTheDocument(),
58+
{ timeout: 3000 },
59+
);
60+
61+
const text = main.textContent ?? "";
62+
expect(text).toContain("Recent alerts");
63+
expect(text).toContain("(1)");
64+
expect(text).not.toContain("最近告警");
65+
66+
const labels = [...main.querySelectorAll("[aria-label]")].map(
67+
(el) => el.getAttribute("aria-label") ?? "",
68+
);
69+
expect(labels.length).toBeGreaterThan(0);
70+
for (const label of labels) expect(label).not.toMatch(CJK);
71+
expect(labels.join(" | ")).toContain("Alerts");
72+
});
73+
74+
it("上游概况健康度分布的 aria-label 为英文(含四态插值)", () => {
75+
const credentials = [makeCredential({}) as Credential];
76+
renderEn(<PoolOverview credentials={credentials} now={Date.now() / 1000} />);
77+
78+
const label = screen.getByTestId("pool-overview").querySelector("[aria-label]");
79+
const text = label?.getAttribute("aria-label") ?? "";
80+
expect(text).toMatch(/Health distribution/);
81+
expect(text).not.toMatch(CJK);
82+
});
83+
});

0 commit comments

Comments
 (0)