-
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 Funding Received form #3246
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
324aa30
feat: adds state for received funding
fpigeonjr 4e020d1
chore: wip
fpigeonjr d2dbd1f
feat: add form validation
weimiao67 6980888
fix: fixed validation bug
weimiao67 ccfc006
refactor: wip, refactor state
weimiao67 017220d
feat: adds api call for funding received
weimiao67 ceba0cd
feat: added api calls for both forms
fpigeonjr 5a44e6b
Merge branch 'main' into OPS-310/3100_CAN_funding_received_form
weimiao67 0bd9d3f
test: adds unit and e2e test
weimiao67 56444d1
chore: fix linting
fpigeonjr bc5d4a0
feat: add state for funding recieved table and updated currency input…
fpigeonjr bb01342
chore: remove onlys from test
fpigeonjr 4191f7d
Merge branch 'main' into OPS-310/3100_CAN_funding_received_form
fpigeonjr 7069041
fix: handle optional chaining for created_by_user in funding received…
fpigeonjr 717dacd
test: update funding received form tests and assertions
fpigeonjr 1519d26
chore: removed unneeded state change
weimiao67 12ce375
chore: removed debug code section
weimiao67 206b0ff
style: fixed margin on table
weimiao67 b5c5f59
style: adds rounded corners to line bar
weimiao67 bf1d797
Merge branch 'main' into OPS-310/3100_CAN_funding_received_form
fpigeonjr 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
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 was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
frontend/src/components/CANs/CANFundingReceivedForm/CanFundingReceivedForm.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,80 @@ | ||
import CurrencyInput from "../../UI/Form/CurrencyInput"; | ||
import TextArea from "../../UI/Form/TextArea"; | ||
import icons from "../../../uswds/img/sprite.svg"; | ||
|
||
/** | ||
* @typedef {Object} CANFundingReceivedFormProps | ||
* @property {(arg: string) => string} cn | ||
* @property {Object} res | ||
* @property {string} receivedFundingAmount | ||
* @property {(e: React.FormEvent<HTMLFormElement>) => void} handleSubmit | ||
* @property {(name: string, value: string) => void} runValidate | ||
* @property { React.Dispatch<React.SetStateAction<string>>} setReceivedFundingAmount | ||
* @property {string} notes | ||
* @property { React.Dispatch<React.SetStateAction<string>>} setNotes | ||
*/ | ||
|
||
/** | ||
* @component - The CAN Funding Received Form component. | ||
* @param {CANFundingReceivedFormProps} props | ||
* @returns {JSX.Element} - The component JSX. | ||
*/ | ||
|
||
const CANFundingReceivedForm = ({ | ||
cn, | ||
res, | ||
runValidate, | ||
handleSubmit, | ||
receivedFundingAmount, | ||
setReceivedFundingAmount, | ||
notes, | ||
setNotes | ||
}) => { | ||
const isFormInValid = !receivedFundingAmount || res.hasErrors("funding-received-amount"); | ||
const fillColor = !isFormInValid ? "#005ea2" : "#757575"; | ||
|
||
return ( | ||
<form | ||
onSubmit={(e) => { | ||
handleSubmit(e); | ||
}} | ||
> | ||
<div style={{ width: "383px" }}> | ||
<CurrencyInput | ||
name="funding-received-amount" | ||
label="Funding Received" | ||
onChange={(name, value) => { | ||
runValidate("funding-received-amount", value); | ||
}} | ||
setEnteredAmount={setReceivedFundingAmount} | ||
value={receivedFundingAmount || ""} | ||
messages={res.getErrors("funding-received-amount")} | ||
className={`${cn("funding-received-amount")} margin-top-0`} | ||
/> | ||
<TextArea | ||
maxLength={75} | ||
name="notes" | ||
label="Notes (optional)" | ||
value={notes} | ||
onChange={(name, value) => setNotes(value)} | ||
textAreaStyle={{ height: "51px" }} | ||
/>{" "} | ||
</div> | ||
<button | ||
className="usa-button usa-button--outline margin-top-4" | ||
disabled={isFormInValid} | ||
data-cy="add-funding-received-btn" | ||
> | ||
<svg | ||
className="height-2 width-2 margin-right-05 cursor-pointer" | ||
style={{ fill: fillColor }} | ||
> | ||
<use xlinkHref={`${icons}#add`}></use> | ||
</svg> | ||
Add Funding Received | ||
</button> | ||
</form> | ||
); | ||
}; | ||
|
||
export default CANFundingReceivedForm; |
78 changes: 78 additions & 0 deletions
78
frontend/src/components/CANs/CANFundingReceivedForm/CanFundingReceivedForm.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,78 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
import CANFundingReceivedForm from "./CanFundingReceivedForm"; | ||
|
||
describe("CANFundingReceivedForm", () => { | ||
let user; | ||
const defaultProps = { | ||
cn: vi.fn(), | ||
res: { | ||
hasErrors: vi.fn().mockReturnValue(false), | ||
getErrors: vi.fn().mockReturnValue([]) | ||
}, | ||
receivedFundingAmount: "", | ||
handleSubmit: vi.fn(), | ||
runValidate: vi.fn(), | ||
setReceivedFundingAmount: vi.fn(), | ||
notes: "", | ||
setNotes: vi.fn() | ||
}; | ||
|
||
beforeEach(() => { | ||
user = userEvent.setup(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("renders the form correctly", () => { | ||
render(<CANFundingReceivedForm {...defaultProps} />); | ||
|
||
expect(screen.getByLabelText(/Funding Received/i)).toBeInTheDocument(); | ||
expect(screen.getByLabelText(/Notes \(optional\)/i)).toBeInTheDocument(); | ||
expect(screen.getByRole("button", { name: /Add Funding Received/i })).toBeInTheDocument(); | ||
}); | ||
|
||
it("calls setNotes when typing in notes field", async () => { | ||
render(<CANFundingReceivedForm {...defaultProps} />); | ||
const textarea = screen.getByLabelText(/Notes \(optional\)/i); | ||
|
||
await user.type(textarea, "Test note"); | ||
expect(defaultProps.setNotes).toHaveBeenCalledTimes(9); | ||
}); | ||
|
||
it("calls setReceivedFundingAmount when typing amount", async () => { | ||
render(<CANFundingReceivedForm {...defaultProps} />); | ||
const input = screen.getByLabelText(/Funding Received/i); | ||
|
||
await user.type(input, "1000"); | ||
|
||
expect(defaultProps.setReceivedFundingAmount).toHaveBeenCalledWith(1000); | ||
}); | ||
|
||
it("calls handleSubmit when form is submitted", async () => { | ||
render( | ||
<CANFundingReceivedForm | ||
{...defaultProps} | ||
receivedFundingAmount="1000" | ||
/> | ||
); | ||
|
||
await user.click(screen.getByRole("button", { name: /Add Funding Received/i })); | ||
|
||
expect(defaultProps.handleSubmit).toHaveBeenCalled(); | ||
}); | ||
|
||
it("disables submit button when form is invalid", () => { | ||
render( | ||
<CANFundingReceivedForm | ||
{...defaultProps} | ||
res={{ | ||
...defaultProps.res, | ||
hasErrors: vi.fn().mockReturnValue(true) | ||
}} | ||
/> | ||
); | ||
|
||
expect(screen.getByRole("button", { name: /Add Funding Received/i })).toBeDisabled(); | ||
}); | ||
}); |
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 "./CanFundingReceivedForm"; |
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.
⭐ nice addition @weimiao67