-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds CAN budget form #3212
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
88d62b4
feat: adds can budget form
Santi-3rd 6402c44
feat: adds CANBudgetForm
fpigeonjr 8b518bf
feat: starts can budget submit
fpigeonjr 1b67894
feat: adds post patch logic
fpigeonjr 4ab1c3a
feat: adds validation
fpigeonjr 70639f7
feat: adds reset to validation suite
fpigeonjr 5d396b0
test: adds e2e for can budget form
maiyerlee 0cc9d98
test: adds can budget form component test
fpigeonjr f44582b
style: match figma design
fpigeonjr fb540e9
Merge branch 'main' into OPS-310/3099_CAN_budget_form
fpigeonjr 3632c19
Merge branch 'main' into OPS-310/3099_CAN_budget_form
maiyerlee fb7f1da
chore: updates tag on CAN funding calls
maiyerlee fd7f5f8
Merge branch 'main' into OPS-310/3099_CAN_budget_form
maiyerlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
60 changes: 60 additions & 0 deletions
60
frontend/src/components/CANs/CANBudgetForm/CANBudgetForm.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,60 @@ | ||
import CurrencyInput from "../../UI/Form/CurrencyInput"; | ||
import icons from "../../../uswds/img/sprite.svg"; | ||
|
||
/** | ||
* @typedef {Object} CANBudgetFormProps | ||
* @property {string} budgetAmount | ||
* @property {(arg: string) => string} cn | ||
* @property {Object} res | ||
* @property {number} fiscalYear | ||
* @property {(e: React.FormEvent<HTMLFormElement>) => void} handleAddBudget | ||
* @property {(name: string, value: string) => void} runValidate | ||
* @property { React.Dispatch<React.SetStateAction<string>>} setBudgetAmount | ||
*/ | ||
|
||
/** | ||
* @component - The CAN Budget Form component. | ||
* @param {CANBudgetFormProps} props | ||
* @returns {JSX.Element} - The component JSX. | ||
*/ | ||
const CANBudgetForm = ({ budgetAmount, cn, res, fiscalYear, handleAddBudget, runValidate, setBudgetAmount }) => { | ||
const fillColor = budgetAmount ? "#005ea2" : "#757575"; | ||
|
||
return ( | ||
<form | ||
onSubmit={(e) => { | ||
handleAddBudget(e); | ||
setBudgetAmount(""); | ||
}} | ||
> | ||
<div style={{ width: "383px" }}> | ||
<CurrencyInput | ||
name="budget-amount" | ||
label={`FY ${fiscalYear} CAN Budget`} | ||
onChange={(name, value) => { | ||
runValidate("budget-amount", value); | ||
}} | ||
setEnteredAmount={setBudgetAmount} | ||
value={budgetAmount || ""} | ||
messages={res.getErrors("budget-amount")} | ||
className={cn("budget-amount")} | ||
/> | ||
</div> | ||
<button | ||
id="add-fy-budget" | ||
className="usa-button usa-button--outline margin-top-4" | ||
disabled={!budgetAmount} | ||
data-cy="add-fy-budget" | ||
> | ||
<svg | ||
className="height-2 width-2 margin-right-05 cursor-pointer" | ||
style={{ fill: fillColor }} | ||
> | ||
<use xlinkHref={`${icons}#add`}></use> | ||
</svg> | ||
Add FY Budget | ||
</button> | ||
</form> | ||
); | ||
}; | ||
export default CANBudgetForm; |
72 changes: 72 additions & 0 deletions
72
frontend/src/components/CANs/CANBudgetForm/CANBudgetForm.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,72 @@ | ||
import { describe, test, expect, vi } from "vitest"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import CANBudgetForm from "./CANBudgetForm"; | ||
|
||
describe("CANBudgetForm", () => { | ||
const defaultProps = { | ||
budgetAmount: "", | ||
cn: (name) => name, | ||
res: { getErrors: () => [] }, | ||
fiscalYear: 2024, | ||
handleAddBudget: vi.fn(), | ||
runValidate: vi.fn(), | ||
setBudgetAmount: vi.fn() | ||
}; | ||
|
||
test("renders with required props", () => { | ||
render(<CANBudgetForm {...defaultProps} />); | ||
expect(screen.getByLabelText(/FY 2024 CAN Budget/i)).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: /add fy budget/i })).toBeInTheDocument(); | ||
}); | ||
|
||
test("button is disabled when budgetAmount is empty", () => { | ||
render(<CANBudgetForm {...defaultProps} />); | ||
expect(screen.getByRole("button", { name: /add fy budget/i })).toBeDisabled(); | ||
}); | ||
|
||
test("button is enabled when budgetAmount has value", () => { | ||
render( | ||
<CANBudgetForm | ||
{...defaultProps} | ||
budgetAmount="1000" | ||
/> | ||
); | ||
expect(screen.getByRole("button", { name: /add fy budget/i })).toBeEnabled(); | ||
}); | ||
|
||
test("calls handleAddBudget and setBudgetAmount on form submission", async () => { | ||
const user = userEvent.setup(); | ||
render( | ||
<CANBudgetForm | ||
{...defaultProps} | ||
budgetAmount="1000" | ||
/> | ||
); | ||
|
||
await user.click(screen.getByRole("button", { name: /add fy budget/i })); | ||
|
||
expect(defaultProps.handleAddBudget).toHaveBeenCalled(); | ||
expect(defaultProps.setBudgetAmount).toHaveBeenCalledWith(""); | ||
}); | ||
|
||
test("calls runValidate when currency input changes", () => { | ||
render(<CANBudgetForm {...defaultProps} />); | ||
|
||
fireEvent.change(screen.getByLabelText(/FY 2024 CAN Budget/i), { | ||
target: { value: "1000" } | ||
}); | ||
|
||
expect(defaultProps.runValidate).toHaveBeenCalledWith("budget-amount", "1,000"); | ||
}); | ||
|
||
test("displays validation errors when present", () => { | ||
const propsWithError = { | ||
...defaultProps, | ||
res: { getErrors: () => ["This is required information"] } | ||
}; | ||
|
||
render(<CANBudgetForm {...propsWithError} />); | ||
expect(screen.getByText("This is required information")).toBeInTheDocument(); | ||
}); | ||
}); |
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 "./CANBudgetForm" |
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,11 @@ | ||
import { create, test, enforce, only } from "vest"; | ||
|
||
const suite = create((data = {}, fieldName) => { | ||
only(fieldName); | ||
|
||
test("budget-amount", "This is required information", () => { | ||
enforce(data["budget-amount"]).isNotBlank(); | ||
}); | ||
}); | ||
|
||
export default suite; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you will want to add
CanFunding
tag to this list. That way when you update the funding thegetCanFundingSummary
will re-fetch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!