Skip to content

Commit 8008bc0

Browse files
committed
chore(dashboard): fix stale trend-chart docstring + dedupe All-range test mock
Adversarial-review follow-ups to PR #1257: - frontend/src/dashboard.ts: the loadSavingsTrendChart docstring still described the pre-QA-2.3 "empty windows render labelled axes" behaviour; the shipped code (lines 1083-1098) shows a filter-aware empty-state banner instead. Reconciled the docstring to describe the actual three branches (data / empty / fetch-error). - frontend/src/__tests__/dashboard.test.ts: the new "All range sends ~365d start" test set mockResolvedValue twice with a mockClear() in between. mockClear() resets call history but NOT mock return values, so the first set was dead code. Collapsed to a single mockResolvedValue + mockClear with a clarifying comment. 97 dashboard tests pass, tsc clean. No behaviour change.
1 parent 7852184 commit 8008bc0

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎frontend/src/__tests__/dashboard.test.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,13 +884,12 @@ describe('Dashboard Module', () => {
884884
bAll.textContent = 'All';
885885
document.body.appendChild(bAll);
886886
setupSavingsTrendHandlers();
887+
// Override the beforeEach default of empty data_points so the chart
888+
// actually renders -- the test asserts the empty-state stays hidden.
887889
(api.getSavingsAnalytics as jest.Mock).mockResolvedValue({
888890
data_points: [{ timestamp: new Date().toISOString(), cumulative_savings: 500, total_savings: 50, total_upfront: 0, purchase_count: 1 }],
889891
});
890892
(api.getSavingsAnalytics as jest.Mock).mockClear();
891-
(api.getSavingsAnalytics as jest.Mock).mockResolvedValue({
892-
data_points: [{ timestamp: new Date().toISOString(), cumulative_savings: 500, total_savings: 50, total_upfront: 0, purchase_count: 1 }],
893-
});
894893

895894
bAll.click();
896895
await new Promise(r => setTimeout(r, 0));

‎frontend/src/dashboard.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,11 +1003,14 @@ export function formatTrendAxisTick(tsMs: number, intervalHint: 'hourly' | 'dail
10031003

10041004
/**
10051005
* Load the savings-over-time trend chart for the dashboard. Fetches the
1006-
* history analytics endpoint with the currently-selected range and
1007-
* renders a line chart of cumulative savings spanning the full selected
1008-
* window on the x-axis (QA row 405, step 3.1). Empty windows render
1009-
* labelled axes rather than a "no data" stub; only fetch failures use
1010-
* the error stub.
1006+
* history analytics endpoint with the currently-selected range and renders
1007+
* a line chart of cumulative savings spanning the full selected window on
1008+
* the x-axis (QA row 405, step 3.1). When the response is empty (QA 2.3
1009+
* supersedes QA 3.1's earlier empty-axes suggestion), the canvas is hidden
1010+
* and an empty-state banner is shown: a filter-aware "No savings history
1011+
* for <filter>" when a provider or account chip is active, otherwise the
1012+
* generic "No purchase history yet." Fetch failures hide the canvas and
1013+
* show the "Savings history is not available yet." stub instead.
10111014
*/
10121015
export async function loadSavingsTrendChart(): Promise<void> {
10131016
const canvas = document.getElementById('savings-trend-chart') as HTMLCanvasElement | null;

0 commit comments

Comments
 (0)