-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ adds Budget Summary Card (#2974)
* feat: BudgetSummaryCard --------- Co-authored-by: Santi-3rd <[email protected]>
- Loading branch information
Showing
9 changed files
with
195 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
frontend/src/components/CANs/CANSummaryCards/CANSummaryCards.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import BudgetSummaryCard from "../../UI/SummaryCard/BudgetSummaryCard"; | ||
|
||
/** | ||
* @component | ||
* @param {Object} props - Properties passed to component | ||
* @param {number} props.fiscalYear - The fiscal year. | ||
* @returns {JSX.Element} - The CANSummaryCards component. | ||
*/ | ||
const CANSummaryCards = ({ fiscalYear }) => { | ||
return ( | ||
<div className="display-flex flex-justify"> | ||
<p> Summary Cards Left</p> | ||
<BudgetSummaryCard | ||
title={`FY ${fiscalYear} CANs Available Budget *`} | ||
totalSpending={1_500_000} | ||
totalFunding={2_000_000} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CANSummaryCards; |
3 changes: 3 additions & 0 deletions
3
frontend/src/components/CANs/CANSummaryCards/CANSummaryCards.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
describe("CANSummaryCards", () => { | ||
it.todo("renders all summary cards", () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "./CANSummaryCards"; |
96 changes: 96 additions & 0 deletions
96
frontend/src/components/UI/SummaryCard/BudgetSummaryCard/BudgetSummaryCard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import CurrencyFormat from "react-currency-format"; | ||
import CANFundingBar from "../../../CANs/CANFundingBar"; | ||
import CurrencyWithSmallCents from "../../CurrencyWithSmallCents/CurrencyWithSmallCents"; | ||
import RoundedBox from "../../RoundedBox"; | ||
import Tag from "../../Tag"; | ||
/** | ||
* @component | ||
* @param {Object} props - Properties passed to component | ||
* @param {string} props.title - The title of the card. | ||
* @param {number} props.totalSpending - The total spending. | ||
* @param {number} props.totalFunding - The total funding. | ||
* @returns {JSX.Element} - The BudgetSummaryCard component. | ||
*/ | ||
const BudgetSummaryCard = ({ title, totalSpending, totalFunding }) => { | ||
const overBudget = totalSpending > totalFunding; | ||
const remainingBudget = overBudget ? 0 : totalFunding - totalSpending; | ||
const graphData = [ | ||
{ | ||
id: 1, | ||
value: totalSpending, | ||
color: overBudget ? "var(--feedback-error)" : "var(--data-viz-budget-graph-2)" | ||
}, | ||
{ | ||
id: 2, | ||
value: remainingBudget, | ||
color: overBudget ? "var(--feedback-error)" : "var(--data-viz-budget-graph-1)" | ||
} | ||
]; | ||
|
||
return ( | ||
<RoundedBox | ||
className={"padding-y-205 padding-x-4 display-inline-block"} | ||
dataCy={`budget-summary-card`} | ||
style={{ height: "14.5rem" }} | ||
> | ||
<h3 | ||
className="margin-0 margin-bottom-2 font-12px text-base-dark text-normal" | ||
style={{ whiteSpace: "pre-line", lineHeight: "20px" }} | ||
> | ||
{title} | ||
</h3> | ||
|
||
<div className="font-32px margin-0 display-flex flex-justify flex-align-end"> | ||
<CurrencyWithSmallCents | ||
amount={remainingBudget} | ||
dollarsClasses="font-sans-xl text-bold margin-bottom-0" | ||
centsStyles={{ fontSize: "10px" }} | ||
/> | ||
{overBudget ? ( | ||
<Tag tagStyle={"lightTextRedBackground"}> | ||
<FontAwesomeIcon | ||
icon={faTriangleExclamation} | ||
title="Over Budget" | ||
/>{" "} | ||
Over Budget | ||
</Tag> | ||
) : ( | ||
<Tag tagStyle={"budgetAvailable"}>Available</Tag> | ||
)} | ||
</div> | ||
<div | ||
id="currency-summary-card" | ||
className="margin-top-2" | ||
> | ||
<CANFundingBar | ||
data={graphData} | ||
isStriped={true} | ||
overBudget={overBudget} | ||
/> | ||
</div> | ||
<div className="font-12px margin-top-2 display-flex flex-justify-end"> | ||
<div> | ||
Spending {""} | ||
<CurrencyFormat | ||
value={totalSpending || 0} | ||
displayType={"text"} | ||
thousandSeparator={true} | ||
prefix={"$"} | ||
renderText={(totalSpending) => <span>{totalSpending}</span>} | ||
/>{" "} | ||
of{" "} | ||
<CurrencyFormat | ||
value={totalFunding || 0} | ||
displayType={"text"} | ||
thousandSeparator={true} | ||
prefix={"$"} | ||
renderText={(totalFunding) => <span>{totalFunding}</span>} | ||
/> | ||
</div> | ||
</div> | ||
</RoundedBox> | ||
); | ||
}; | ||
export default BudgetSummaryCard; |
53 changes: 53 additions & 0 deletions
53
frontend/src/components/UI/SummaryCard/BudgetSummaryCard/BudgetSummaryCard.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { describe, it, expect } from "vitest"; | ||
import BudgetSummaryCard from "./BudgetSummaryCard"; | ||
|
||
describe("BudgetSummaryCard", () => { | ||
const defaultProps = { | ||
title: "Budget Summary", | ||
totalSpending: 15000, | ||
totalFunding: 20000 | ||
}; | ||
|
||
it("renders with all required props", () => { | ||
render(<BudgetSummaryCard {...defaultProps} />); | ||
|
||
expect(screen.getByText("Budget Summary")).toBeInTheDocument(); | ||
expect(screen.getByText("$ 5,000")).toBeInTheDocument(); | ||
expect(screen.getByText("Available")).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays over budget warning when spending exceeds funding", () => { | ||
const overBudgetProps = { | ||
...defaultProps, | ||
totalSpending: 25000, | ||
totalFunding: 20000 | ||
}; | ||
|
||
render(<BudgetSummaryCard {...overBudgetProps} />); | ||
|
||
expect(screen.getByTitle("Over Budget")).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays correct spending and funding amounts", () => { | ||
render(<BudgetSummaryCard {...defaultProps} />); | ||
|
||
const spendingText = screen.getByText(/\$15,000/); | ||
const fundingText = screen.getByText(/\$20,000/); | ||
|
||
expect(spendingText).toBeInTheDocument(); | ||
expect(fundingText).toBeInTheDocument(); | ||
}); | ||
|
||
it("handles zero values correctly", () => { | ||
const zeroProps = { | ||
...defaultProps, | ||
totalSpending: 0, | ||
totalFunding: 0 | ||
}; | ||
|
||
render(<BudgetSummaryCard {...zeroProps} />); | ||
|
||
expect(screen.queryAllByText("$0")).toHaveLength(2); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
frontend/src/components/UI/SummaryCard/BudgetSummaryCard/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from "./BudgetSummaryCard" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters