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

it("formats sparkline values through the card's own format/asset, not raw numbers (#709)", () => {
render(
<StatCard
label="Lifetime earnings"
status="loaded"
value={8420}
format="currency"
asset="USDC"
sparkline={[1234.5, 4000, 6200, 8420]}
/>,
);
const svg = screen.getByRole("img");
// Previously announced "trending up from 1234.5 to 8420" via describeTrend's
// String(v) fallback -- no currency symbol or locale grouping, unlike the
// visible "$8,420.00" value right next to it.
expect(svg).toHaveAccessibleName(/trending up from 1,234.5 USDC to 8,420 USDC/);
});
});
12 changes: 10 additions & 2 deletions src/components/ui/StatCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,16 @@ export function StatCard({
<div data-testid="statcard-sparkline" className="text-indigo-500 dark:text-indigo-400">
{/* 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} />
from …" rather than as an unlabelled graphic. formatValue is
threaded through too (#709): without it, describeTrend falls
back to String(v), so a currency card like "Lifetime earnings"
announced "trending up from 1234.5 to 8420" with no currency or
locale grouping, while the visible value reads "$8,420.00". */}
<Sparkline
data={sparkline}
label={label}
formatValue={(v) => formatValue(v, format, asset, locale).display}
/>
</div>
)}
</div>,
Expand Down