fix(ui): show a malformed generated_at stamp as-is on the Price Data Reload card

This commit is contained in:
mateo-berri 2026-09-07 17:28:58 -07:00
parent 0710231acc
commit 6c1bba54c2
2 changed files with 15 additions and 5 deletions

View file

@ -75,6 +75,19 @@ describe("PriceDataReload", () => {
expect(screen.getByText(new Date(provenance.loaded_at).toLocaleString())).toBeInTheDocument();
});
it("shows a malformed generated_at stamp as-is instead of Invalid Date", async () => {
vi.mocked(getModelCostMapSource).mockResolvedValue({
...remoteSource,
...provenance,
generated_at: "yesterday-ish",
} as never);
render(<PriceDataReload accessToken="sk-test" />);
expect(await screen.findByText("Generated at:")).toBeInTheDocument();
expect(screen.getByText("yesterday-ish")).toBeInTheDocument();
expect(screen.queryByText("Invalid Date")).not.toBeInTheDocument();
});
it("hides the provenance rows when the loaded map carries no stamp", async () => {
render(<PriceDataReload accessToken="sk-test" />);

View file

@ -99,11 +99,8 @@ const isValidReloadInterval = (value: number) => {
const formatDateTime = (dateTimeString: string | null) => {
if (!dateTimeString) return "Never";
try {
return new Date(dateTimeString).toLocaleString();
} catch {
return dateTimeString;
}
const parsed = new Date(dateTimeString);
return Number.isNaN(parsed.getTime()) ? dateTimeString : parsed.toLocaleString();
};
const CostMapProvenanceRows: React.FC<{ sourceInfo: CostMapSourceInfo }> = ({ sourceInfo }) => (