-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ieee 272 implement item incident form (#503)
* incident form init * implementing form components * fixing form style * fixing position of menu items * implement back button * adding helper text for radio * fixing button * cleaning up unused vars * adding report broken lost button * init test * fixing link * reset form on successful submission * setting up testing * fix test * fixing tests * removing unused code * adding name to readme * fix type error * padding qty to new page & adding snackbar * rewriting formik with map * fixing responsive issues on form * fixing checkedout tables style * adding map to radio options * using map in form * fixing textfield width * fixing validation onchange * adding more unit tests to check for rendering of form components and submit button * adding more padding between form elements and labels * removing inline styles (sorry bad habitsgit status) * removing unused code and console.log & changing url format a little bit to pass more info about hardware for incident form * added yup validation to check if the input string is 0 for qty, is so don't submit the form * adding conditional redirects * cleaning up code * fixing tests for incident form to account for conditional rendering of the component when there are search params * fixing type, had to use any bc not sure about how the URLSearchParams typing works * fixing dependencies & adding const * used to bypass react-hooks/exhaustive-deps so that dependencies don't need to be in useEffect array, so that the useEffect will fire on first render * removing unused code --------- Co-authored-by: Mustafa <mus2003.abdul@gmail.com>
- Loading branch information
1 parent
879689d
commit a7222e1
Showing
10 changed files
with
637 additions
and
62 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
1 change: 1 addition & 0 deletions
1
hackathon_site/dashboard/frontend/src/assets/images/icons/arrow-left-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
16 changes: 0 additions & 16 deletions
16
hackathon_site/dashboard/frontend/src/pages/IncidentForm/IncidentForm.js
This file was deleted.
Oops, something went wrong.
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,74 @@ | ||
@import "assets/abstracts/mixins.scss"; | ||
@import "assets/abstracts/variables.scss"; | ||
|
||
.arrowIcon { | ||
width: 50px; | ||
height: 50px; | ||
padding: 10px; | ||
align-self: flex-start; | ||
|
||
transform: translateX(0px), scale(1); | ||
transition: transform ease-in-out 300ms; | ||
|
||
&:hover { | ||
transform: translateX(-10px); | ||
transition: transform ease-in-out 300ms; | ||
} | ||
|
||
&:active { | ||
transform: scale(0.8); | ||
transition: transform 300ms; | ||
} | ||
} | ||
|
||
.formContainer { | ||
display: flex; | ||
flex-direction: column; | ||
width: max(40vw, 640px); | ||
|
||
@include responsive(md-down) { | ||
width: 100%; | ||
} | ||
} | ||
|
||
.formComponentContainer { | ||
all: unset; | ||
padding-bottom: 20px; | ||
} | ||
|
||
.card { | ||
align-self: center; | ||
} | ||
|
||
.cardContent { | ||
padding: 20px; | ||
} | ||
|
||
.pageContent { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
} | ||
|
||
.dropdown { | ||
width: 200px; | ||
|
||
@include responsive(md-down) { | ||
width: 30%; | ||
} | ||
} | ||
|
||
.textboxFill { | ||
width: 100%; | ||
} | ||
|
||
.submitButton { | ||
align-self: center; | ||
width: fit-content; | ||
margin-top: 10px; | ||
} | ||
|
||
.titleMargin { | ||
margin-bottom: 20px; | ||
} |
10 changes: 0 additions & 10 deletions
10
hackathon_site/dashboard/frontend/src/pages/IncidentForm/IncidentForm.test.js
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
hackathon_site/dashboard/frontend/src/pages/IncidentForm/IncidentForm.test.tsx
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 { render, screen } from "testing/utils"; // Import your testing utilities here | ||
import IncidentForm from "./IncidentForm"; | ||
import configureStore, { MockStore } from "redux-mock-store"; | ||
|
||
describe("IncidentForm", () => { | ||
const mockStore = configureStore<any>([]); | ||
let store: MockStore<any>; | ||
|
||
beforeEach(() => { | ||
store = mockStore({ | ||
yourReducerKey: { | ||
id: 10, | ||
quantityRequested: 3, | ||
quantityGranted: 2, | ||
}, | ||
}); | ||
}); | ||
|
||
it("renders correctly when searchParams is empty", () => { | ||
render(<IncidentForm />); | ||
|
||
// Assert that the component renders nothing when searchParams is empty | ||
expect(screen.queryByText("Item Incident Form")).toBeNull(); // Update the text according to your component's content | ||
}); | ||
|
||
it("renders IncidentFormRender when searchParams is not empty", () => { | ||
const mockSearchParams: any = { | ||
get: jest.fn(() => | ||
JSON.stringify({ id: 10, quantityRequested: 3, quantityGranted: 2 }) | ||
), | ||
toString: jest.fn(() => "mockQueryString"), | ||
}; | ||
|
||
jest.spyOn(global, "URLSearchParams").mockImplementation( | ||
() => mockSearchParams | ||
); | ||
|
||
render(<IncidentForm />); | ||
|
||
// Assert that mockSearchParams methods are called | ||
expect(mockSearchParams.toString).toHaveBeenCalled(); | ||
expect(mockSearchParams.get).toHaveBeenCalledWith("data"); | ||
|
||
// Assert that the component renders IncidentFormRender | ||
expect(screen.queryByText("Item Incident Form")).toBeInTheDocument(); // Update the text according to your component's content | ||
|
||
// Renders all form components | ||
const radios = screen.getAllByRole("radio"); | ||
const dropdown = screen.getByTestId("qty-dropdown"); | ||
const textareas = screen.getAllByRole("textbox"); | ||
|
||
expect(radios).toHaveLength(3); // three radio buttons | ||
expect(dropdown).toBeInTheDocument(); // one dropdown | ||
expect(textareas).toHaveLength(3); // three text inputs | ||
|
||
// Renders submit button | ||
const submitButton = screen.getByRole("button", { name: "Submit" }); | ||
expect(submitButton).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.