Skip to content
Open
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
33 changes: 33 additions & 0 deletions src/components/ui/StatCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,37 @@ describe("StatCard — sparkline", () => {
"Earnings history: 4 data points, trending up from 10 to 30, range 10 to 30",
);
});

it("formats sparkline values according to format and asset props (#709)", () => {
render(
<StatCard
label="Lifetime earnings"
status="loaded"
value={8420}
format="currency"
asset="USDC"
sparkline={[1234.5, 2000, 5000, 8420]}
/>,
);
const svg = screen.getByRole("img");
expect(svg).toHaveAccessibleName(
"Lifetime earnings: 4 data points, trending up from 1,234.5 USDC to 8,420 USDC, range 1,234.5 USDC to 8,420 USDC",
);
});

it("formats sparkline values for count format (#709)", () => {
render(
<StatCard
label="Completed tasks"
status="loaded"
value={5000}
format="count"
sparkline={[1000, 2500, 5000]}
/>,
);
const svg = screen.getByRole("img");
expect(svg).toHaveAccessibleName(
"Completed tasks: 3 data points, trending up from 1,000 to 5,000, range 1,000 to 5,000",
);
});
});
8 changes: 6 additions & 2 deletions src/components/ui/StatCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

import { cn, formatCurrency, formatInteger, formatPercent } from "@/lib/utils";
import { isRTLLocale, resolveLocale } from "@/lib/locale";
import { resolveLocale } from "@/lib/locale";
import { ArrowUpRight, ArrowDownRight, AlertCircle } from "lucide-react";
import type { LucideIcon } from "lucide-react";
import { Sparkline } from "./Sparkline";
Expand Down Expand Up @@ -280,7 +280,11 @@ export function StatCard({
{/* The card's own label becomes the sparkline's accessible name, so
the trend is announced as "Earnings: 8 data points, trending up
from …" rather than as an unlabelled graphic. */}
<Sparkline data={sparkline} label={label} />
<Sparkline
data={sparkline}
label={label}
formatValue={(v) => formatValue(v, format, asset, locale).display}
/>
</div>
)}
</div>,
Expand Down