fix(webui): align token usage heatmap

This commit is contained in:
chengyongru
2026-06-08 16:02:12 +08:00
committed by Xubin Ren
parent 631fdb4a46
commit 7510918610
3 changed files with 103 additions and 11 deletions
+41
View File
@@ -119,6 +119,7 @@ const installedAnyGen = {
function renderSettingsView(
options: {
initialSection?: "overview" | "apps" | "advanced" | "models";
initialSettings?: SettingsPayload;
onSettingsChange?: (payload: SettingsPayload) => void;
onNativeEngineRestart?: () => Promise<string>;
} = {},
@@ -128,6 +129,7 @@ function renderSettingsView(
<SettingsView
theme="light"
initialSection={options.initialSection ?? "apps"}
initialSettings={options.initialSettings}
onToggleTheme={() => {}}
onBackToChat={() => {}}
onModelNameChange={() => {}}
@@ -140,6 +142,7 @@ function renderSettingsView(
describe("SettingsView Apps catalog", () => {
afterEach(() => {
vi.useRealTimers();
vi.unstubAllGlobals();
});
@@ -270,6 +273,44 @@ describe("SettingsView Apps catalog", () => {
expect(screen.queryByText("Peak tokens")).not.toBeInTheDocument();
});
it("aligns token activity days with the configured timezone", async () => {
vi.useFakeTimers();
vi.setSystemTime(new Date("2026-06-02T18:00:00Z"));
const payload: SettingsPayload = {
...settingsPayload(),
agent: {
...settingsPayload().agent,
timezone: "Asia/Shanghai",
},
usage: {
days: [
{
date: "2026-06-03",
prompt_tokens: 1200,
completion_tokens: 300,
cached_tokens: 500,
total_tokens: 1500,
requests: 2,
},
],
total_tokens: 1500,
total_tokens_30d: 1500,
total_tokens_365d: 1500,
peak_day_tokens: 1500,
current_streak_days: 1,
longest_streak_days: 1,
active_days_30d: 1,
requests_30d: 2,
updated_at: "2026-06-03T00:00:00Z",
},
};
vi.stubGlobal("fetch", vi.fn(() => new Promise<Response>(() => {})));
renderSettingsView({ initialSection: "overview", initialSettings: payload });
expect(screen.getByLabelText("2026-06-03: 1.5K tokens, 2 requests")).toBeInTheDocument();
});
it("shows context window options in model settings", async () => {
vi.stubGlobal(
"fetch",