From 81dba9da14ffa0f8c7697eda228e9b2710d0dd5e Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Thu, 19 Mar 2026 00:34:16 +1100 Subject: [PATCH] test: stabilize AgentsPageView analytics story date (#23216) ## Summary The `AgentsPageView: Opens Analytics For Admins` story was flaky because the analytics header renders a rolling 30-day date range in the top-right corner. Since that range was based on the current date, the story output changed every day. This change makes the story deterministic by: - adding an optional `analyticsNow` prop to `AgentsPageView` - passing that value through to `AnalyticsPageContent` when the analytics panel is shown - setting a fixed local-noon timestamp in the story so the rendered range label stays stable across timezones --- site/src/pages/AgentsPage/AgentsPageView.stories.tsx | 5 +++++ site/src/pages/AgentsPage/AgentsPageView.tsx | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/site/src/pages/AgentsPage/AgentsPageView.stories.tsx b/site/src/pages/AgentsPage/AgentsPageView.stories.tsx index eb0b360e15..891101d675 100644 --- a/site/src/pages/AgentsPage/AgentsPageView.stories.tsx +++ b/site/src/pages/AgentsPage/AgentsPageView.stories.tsx @@ -5,6 +5,7 @@ import { API } from "api/api"; import type * as TypesGen from "api/typesGenerated"; import type { Chat } from "api/typesGenerated"; import type { ModelSelectorOption } from "components/ai-elements"; +import dayjs from "dayjs"; import { expect, fn, @@ -100,6 +101,9 @@ const mockUsageUsers: TypesGen.ChatCostUsersResponse = { ], }; +// Use local noon so the rendered range label stays stable across timezones. +const fixedAnalyticsNow = dayjs("2026-03-12T12:00:00"); + const oneWeekAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(); const todayTimestamp = new Date().toISOString(); @@ -166,6 +170,7 @@ const meta: Meta = { onToggleSidebarCollapsed: fn(), }, isAgentsAdmin: false, + analyticsNow: fixedAnalyticsNow, archivedFilter: "active" as const, onArchivedFilterChange: fn(), isFetchingNextPage: false, diff --git a/site/src/pages/AgentsPage/AgentsPageView.tsx b/site/src/pages/AgentsPage/AgentsPageView.tsx index 9d630c7968..6a5516d315 100644 --- a/site/src/pages/AgentsPage/AgentsPageView.tsx +++ b/site/src/pages/AgentsPage/AgentsPageView.tsx @@ -3,6 +3,7 @@ import type { ModelSelectorOption } from "components/ai-elements"; import { Button } from "components/Button/Button"; import { ExternalImage } from "components/ExternalImage/ExternalImage"; import { CoderIcon } from "components/Icons/CoderIcon"; +import type { Dayjs } from "dayjs"; import { PanelLeftIcon } from "lucide-react"; import { type FC, useCallback, useMemo } from "react"; import { NavLink, Outlet, useLocation, useNavigate } from "react-router"; @@ -62,6 +63,7 @@ interface AgentsPageViewProps { isFetchingNextPage: boolean; archivedFilter: "active" | "archived"; onArchivedFilterChange: (filter: "active" | "archived") => void; + analyticsNow?: Dayjs; } export const AgentsPageView: FC = ({ @@ -93,6 +95,7 @@ export const AgentsPageView: FC = ({ isFetchingNextPage, archivedFilter, onArchivedFilterChange, + analyticsNow, }) => { const { chatErrorReasons, @@ -179,7 +182,7 @@ export const AgentsPageView: FC = ({ canSetSystemPrompt={isAgentsAdmin} /> ) : sidebarView.panel === "analytics" ? ( - + ) : agentId ? ( ) : (