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
21 changes: 21 additions & 0 deletions frontend/src/__tests__/recommendations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8180,6 +8180,27 @@ describe('Issue #135: SP group parent row rendered in table', () => {
// Should reflect sum: 100 + 200 = 300
expect(groupSavings!.textContent).toContain('$300');
});

test('issue #252: SP group savings does not double-apply the cost-period factor', async () => {
const recs = [
mkSpRec('savings-plans-compute', { id: 'sp-c', savings: 100 }),
mkSpRec('savings-plans-sagemaker', { id: 'sp-s', savings: 200 }),
];
(api.getRecommendations as jest.Mock).mockResolvedValue({ summary: {}, recommendations: recs, regions: [] });
(state.getRecommendations as jest.Mock).mockReturnValue(recs);
(state.getVisibleRecommendations as jest.Mock).mockReturnValue(recs);

// Monthly total is $300. On "yearly" (factor 12) the correct figure is
// $3,600/yr. Pre-fix, scaleCost was applied once outside and again
// inside formatCostForPeriod, yielding $36,000/yr (12x too high).
(state.getCostPeriod as jest.Mock).mockReturnValue('yearly');
await loadRecommendations();

const groupSavings = document.querySelector('.rec-sp-group-savings');
expect(groupSavings).not.toBeNull();
expect(groupSavings!.textContent).toContain('$3600');
expect(groupSavings!.textContent).not.toContain('$36000');
});
});

// ============================================================================
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/recommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3203,8 +3203,9 @@ function buildListMarkup(
const cv = groups.get(ck)!;
spSavingsTotal += Math.max(...cv.map((r) => r.savings));
}
const scaledSpSavings = scaleCost(spSavingsTotal, period) ?? spSavingsTotal;
const spSavingsText = `${formatCostForPeriod(scaledSpSavings, period)}${sfxLabel}`;
// formatCostForPeriod scales internally; passing the already-scaled
// scaledSpSavings here double-applied the period factor (issue #252).
const spSavingsText = `${formatCostForPeriod(spSavingsTotal, period)}${sfxLabel}`;
const sgkAttr = escapeHtml(sgk);
rows.push(`
<tr class="rec-sp-group-row" data-sp-group-key="${sgkAttr}">
Expand Down
Loading