Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/src/api/statsErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async function fetchStatsErrorTrend(
},
);
if (!response.ok) {
throw new Error(`失败趋势加载失败(HTTP ${response.status})`);
throw new Error(tr("失败趋势加载失败(HTTP {0})", [response.status]));
}
return (await response.json()) as StatsErrorTrendResponse;
}
Expand Down
3 changes: 1 addition & 2 deletions web/src/i18n/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ export const TEXT_EN: Record<string, string> = {
"天失败": "days failed",
"天)·": "days) ·",
"失败归因加载失败(HTTP {0})": "Failed to load failure attribution (HTTP {0})",
"失败趋势加载失败(HTTP {0})": "Failed to load failure trend (HTTP {0})",
"完成": "Done",
"官方状态页": "Official status pages",
"官方状态页粒度比本服务的模型级冷却粗、更新也滞后,这里只做解释,不参与选号 / 熔断;本服务实时冷却见「凭证管理」页。数据仅存内存,服务重启后归零。": "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.",
Expand Down Expand Up @@ -1278,8 +1279,6 @@ export const TEXT_EN: Record<string, string> = {
"运行中…": "Running…",
"运行时配置加载失败": "Failed to load runtime settings",
"近": "Last ",
"近 30 天": "Last 30 days",
"近 7 天": "Last 7 days",
"近期事故": "Recent incidents",
"返回": "Back",
"还没有备份": "No backups yet",
Expand Down
83 changes: 83 additions & 0 deletions web/src/pages/__tests__/AlertsUpstreamI18n.en.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { screen, waitFor, within } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { I18nProvider } from "@/i18n";
import { PoolOverview } from "@/components/PoolOverview";
import type { Credential } from "@/api/types";
import { makeCredential, renderPage } from "@/test-utils";
import { AlertsPage } from "../AlertsPage";

const CJK = /[\u4e00-\u9fff]/;

/** 英文态渲染页面(Layout 提供会话与导航,Provider 决定语言)。 */
function renderEn(ui: React.ReactNode) {
return renderPage(<I18nProvider initial="en">{ui}</I18nProvider>, {
username: "root",
is_admin: true,
});
}

function stubFetch(body: unknown) {
const spy = vi.fn(
async () =>
new Response(JSON.stringify(body), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
);
vi.stubGlobal("fetch", spy);
return spy;
}

describe("告警页 / 上游概况:英文态插值文案不再漏中文", () => {
beforeEach(() => {
vi.unstubAllGlobals();
});

it("告警页标题与记录 aria-label 均为英文(含条数插值)", async () => {
stubFetch({
total: 1,
alerts: [
{
id: "alert_1",
ts: 1_700_000_000,
rule: "pool_empty",
severity: "critical",
scope: "pool",
message: "No credentials available",
detail: "{}",
delivered: 1,
delivery_error: null,
resolved_at: null,
},
],
});
renderEn(<AlertsPage />);
const main = await screen.findByRole("main");
await waitFor(
() => expect(within(main).getByTestId("alerts-table")).toBeInTheDocument(),
{ timeout: 3000 },
);

const text = main.textContent ?? "";
expect(text).toContain("Recent alerts");
expect(text).toContain("(1)");
expect(text).not.toContain("最近告警");

const labels = [...main.querySelectorAll("[aria-label]")].map(
(el) => el.getAttribute("aria-label") ?? "",
);
expect(labels.length).toBeGreaterThan(0);
for (const label of labels) expect(label).not.toMatch(CJK);
expect(labels.join(" | ")).toContain("Alerts");
});

it("上游概况健康度分布的 aria-label 为英文(含四态插值)", () => {
const credentials = [makeCredential({}) as Credential];
renderEn(<PoolOverview credentials={credentials} now={Date.now() / 1000} />);

const label = screen.getByTestId("pool-overview").querySelector("[aria-label]");
const text = label?.getAttribute("aria-label") ?? "";
expect(text).toMatch(/Health distribution/);
expect(text).not.toMatch(CJK);
});
});
Loading