Files
nanobot/webui/src/tests/mcp-activity-model.test.ts
T
ZhouandXubin Ren 796e1cb0e6 feat(webui): localize agent activity
Localize frontend-owned activity presentation while preserving raw tool data and current controls. Include locale-aware model memoization and integration with current main.

Co-authored-by: Xubin Ren <52506698+Re-bin@users.noreply.github.com>
2026-09-25 01:50:12 +08:00

52 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { describeMcpActivity } from "@/components/thread/activity/mcp-activity-model";
import i18n, { setAppLanguage } from "@/i18n";
describe("describeMcpActivity", () => {
it.each([
["browser_navigate", { url: "https://example.com/docs" }, "done", "Opened", "example.com/docs"],
["browser_click", { element: "Submit" }, "running", "Clicking", "Submit"],
["browser_snapshot", {}, "done", "Inspected page", undefined],
["browser_screenshot", {}, "done", "Captured screenshot", undefined],
["browser_press_key", { key: "Enter" }, "error", "Could not press", "Enter"],
] as const)("turns %s into user-facing activity copy", (tool, args, status, action, target) => {
expect(describeMcpActivity(tool, args, status, i18n.t)).toEqual({ action, target });
});
it("does not expose entered text in the activity timeline", () => {
expect(describeMcpActivity(
"browser_fill",
{ element: "Password", text: "not-for-the-timeline" },
"done",
i18n.t,
)).toEqual({ action: "Entered text", target: "in Password" });
});
it("drops URL credentials and query parameters from browser activity", () => {
expect(describeMcpActivity(
"browser_navigate",
{ url: "https://user:password@example.com/docs?token=private#section" },
"done",
i18n.t,
)).toEqual({ action: "Opened", target: "example.com/docs" });
});
it("humanizes unknown tool names instead of exposing function syntax", () => {
expect(describeMcpActivity("browser_export_report", {}, "done", i18n.t)).toEqual({
action: "Export report completed",
});
});
it("localizes browser actions without translating targets", async () => {
await setAppLanguage("zh-CN");
expect(describeMcpActivity(
"browser_fill",
{ element: "Password", text: "not-for-the-timeline" },
"done",
i18n.t,
)).toEqual({ action: "已输入文本", target: "至 Password" });
});
});