Skip to content
Merged
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
20 changes: 20 additions & 0 deletions frontend/src/__tests__/dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ describe('Dashboard Module', () => {
expect(summary?.innerHTML).toContain('YTD Savings');
});

test('formats fractional current_coverage with one decimal (not raw float)', async () => {
(api.getDashboardSummary as jest.Mock).mockResolvedValue({
potential_monthly_savings: 0,
total_recommendations: 1,
active_commitments: 1,
committed_monthly: 100,
current_coverage: 0.14648736342042862,
target_coverage: 80,
ytd_savings: 0,
by_service: {}
});
(api.getUpcomingPurchases as jest.Mock).mockResolvedValue({ purchases: [] });

await loadDashboard();

const summary = document.getElementById('summary');
expect(summary?.innerHTML).toContain('0.1%');
expect(summary?.innerHTML).not.toContain('0.14648736342042862');
});

test('renders the merged per-service savings chart', async () => {
(api.getDashboardSummary as jest.Mock).mockResolvedValue({
potential_monthly_savings: 1000,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ function renderDashboardSummary(data: DashboardSummary, recs: readonly LocalReco
// When no recommendations and no commitments exist, "100% coverage" is
// misleading — nothing is being tracked. Show a dash instead.
const nothingTracked = !data.total_recommendations && !data.active_commitments;
const coverageValue = nothingTracked ? '—' : `${data.current_coverage || 0}%`;
const coverageDetail = nothingTracked ? 'No services tracked' : `Target: ${data.target_coverage || 80}%`;
const coverageValue = nothingTracked ? '—' : `${(data.current_coverage || 0).toFixed(1)}%`;
const coverageDetail = nothingTracked ? 'No services tracked' : `Target: ${(data.target_coverage || 80).toFixed(1)}%`;

// Render KPI tiles via DOM construction (textContent / appendChild)
// rather than an innerHTML template literal, per the issue #340 plan's
Expand Down
4 changes: 4 additions & 0 deletions internal/api/handler_purchases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,10 @@ func TestHandler_getPurchaseDetails_NotFound_IsClientError(t *testing.T) {
Email: "admin@example.com",
}
mockAuth.On("ValidateSession", ctx, "admin-token").Return(adminSession, nil)
// getPurchaseDetails gates on requirePermission(view, purchases) before
// the GetExecutionByID lookup this test targets. Confer admin via the auth
// mock (the Session struct carries no role field; admin is resolved through
// HasPermissionAPI) so the handler reaches the not-found branch.
mockAuth.grantAdmin()

const missingID = "dddddddd-dddd-dddd-dddd-dddddddddddd"
Expand Down
Loading