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
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,11 @@ describe("MultiYearBudgetaryImpact", () => {
expect(
screen.getByText(mockImpact.budget.budgetary_impact / 1e9),
).toBeInTheDocument();
const expectedBenefitImpact = -Math.abs(
mockImpact.budget.benefit_spending_impact / 1e9,
);
expect(
screen.getByText(mockImpact.budget.benefit_spending_impact / 1e9),
screen.getByText(expectedBenefitImpact.toString()),
).toBeInTheDocument();
expect(
screen.getByText(
Expand Down
13 changes: 10 additions & 3 deletions src/pages/policy/output/budget/MultiYearBudgetaryImpact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ export default function MultiYearBudgetaryImpact(props) {
item.budgetKey ? item.budgetKey : null,
item.formula ? item.formula : null,
),

yearRange: roundToBillions(
item.budgetKey
? impact.budget[item.budgetKey]
: item.formula(impact.budget),
item.budgetKey === "benefit_spending_impact"
? -Math.abs(impact.budget[item.budgetKey])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: I believe this only half-solves the problem

In cases where the government budget loses revenue (e.g., a new benefit program is introduced), the benefits row should be negative, but in cases where the government budget gains revenue (e.g., benefit cuts), it should be positive. This code will always make it positive.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: It's tough to read this nested conditional

Addressing my other comment, can you modify this to be more readable/CLEAN?

: item.budgetKey
? impact.budget[item.budgetKey]
: item.formula(impact.budget),
roundingPrecisionByCountry[metadata.countryId] ||
roundingPrecisionByCountry.default,
),
Expand Down Expand Up @@ -198,6 +201,10 @@ export function getYearlyImpacts(
impact = item.result.budget[budgetKey];
}

if (budgetKey === "benefit_spending_impact") {
impact = -Math.abs(impact);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: Here, too budgetary impacts are always negative when they should be negative only sometimes

}

yearlyImpacts[year] = roundToBillions(
impact,
roundingPrecisionByCountry[countryId] ||
Expand Down
Loading