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
CS - Add frontend support for new job which takes only a quarter as its parameter #52
Changes from 4 commits
71a8b23
62776de
a6437ee
fd68ff7
3aa56d7
692def3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useState } from "react"; | ||
import { Form, Button, Container, Row, Col } from "react-bootstrap"; | ||
|
||
import { quarterRange } from "main/utils/quarterUtilities"; | ||
|
||
import { useSystemInfo } from "main/utils/systemInfo"; | ||
import SingleQuarterDropdown from "../Quarters/SingleQuarterDropdown"; | ||
|
||
const UpdateCoursesByQuarterJobForm = ({ callback }) => { | ||
|
||
const { data: systemInfo } = useSystemInfo(); | ||
|
||
// Stryker disable OptionalChaining | ||
const startQtr = systemInfo?.startQtrYYYYQ || "20211"; | ||
const endQtr = systemInfo?.endQtrYYYYQ || "20214"; | ||
// Stryker enable OptionalChaining | ||
|
||
const quarters = quarterRange(startQtr, endQtr); | ||
|
||
// Stryker disable all : not sure how to test/mock local storage | ||
const localQuarter = localStorage.getItem("BasicSearch.Quarter"); | ||
|
||
const [quarter, setQuarter] = useState(localQuarter || quarters[0].yyyyq); | ||
|
||
const handleSubmit = (event) => { | ||
event.preventDefault(); | ||
console.log("UpdateCoursesJobForm: quarter", quarter); | ||
callback({quarter}); | ||
}; | ||
|
||
// Stryker disable all : Stryker is testing by changing the padding to 0. But this is simply a visual optimization as it makes it look better | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above... it's ok to invoke this for the part of the code that needs Stryker disabled... but you need to confine this to the smallest possible scope. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #57 I suggest what this might look like. |
||
return ( | ||
<Form onSubmit={handleSubmit}> | ||
<Container> | ||
<Row> | ||
<Col md="auto"> | ||
<SingleQuarterDropdown | ||
quarters={quarters} | ||
quarter={quarter} | ||
setQuarter={setQuarter} | ||
controlId={"BasicSearch.Quarter"} | ||
/> | ||
</Col> | ||
</Row> | ||
<Row style={{ paddingTop: 10, paddingBottom: 10 }}> | ||
<Col md="auto"> | ||
<Button variant="primary" type="submit" data-testid="updateCoursesByQuarter"> | ||
Update Courses | ||
</Button> | ||
</Col> | ||
</Row> | ||
</Container> | ||
</Form> | ||
); | ||
}; | ||
|
||
export default UpdateCoursesByQuarterJobForm; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from "react"; | ||
|
||
import UpdateCoursesByQuarterJobForm from "main/components/Jobs/UpdateCoursesByQuarterJobForm"; | ||
import { systemInfoFixtures } from "fixtures/systemInfoFixtures"; | ||
|
||
export default { | ||
title: "components/Jobs/UpdateCoursesByQuarterJobForm", | ||
component: UpdateCoursesByQuarterJobForm, | ||
parameters: { | ||
mockData: [ | ||
{ | ||
url: '/api/systemInfo', | ||
method: 'GET', | ||
status: 200, | ||
response: systemInfoFixtures.showingBoth | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const Template = (args) => { | ||
return <UpdateCoursesByQuarterJobForm {...args} />; | ||
}; | ||
|
||
export const Default = Template.bind({}); | ||
|
||
Default.args = { | ||
callback: (data) => { | ||
console.log("Submit was clicked, data=", data); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { BrowserRouter as Router } from "react-router-dom"; | ||
import UpdateCoursesByQuarterJobForm from "main/components/Jobs/UpdateCoursesByQuarterJobForm"; | ||
import { QueryClient, QueryClientProvider } from "react-query"; | ||
|
||
import axios from "axios"; | ||
import AxiosMockAdapter from "axios-mock-adapter"; | ||
|
||
|
||
const mockedNavigate = jest.fn(); | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useNavigate: () => mockedNavigate | ||
})); | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
describe("UpdateCoursesByQuarterJobForm tests", () => { | ||
|
||
const axiosMock = new AxiosMockAdapter(axios); | ||
|
||
it("renders correctly", async () => { | ||
render( | ||
<QueryClientProvider client={queryClient}> | ||
<Router > | ||
<UpdateCoursesByQuarterJobForm /> | ||
</Router> | ||
</QueryClientProvider> | ||
); | ||
|
||
expect(screen.getByText(/Update Courses/)).toBeInTheDocument(); | ||
}); | ||
|
||
test("renders without crashing when fallback values are used", async () => { | ||
|
||
axiosMock | ||
.onGet("/api/systemInfo") | ||
.reply(200, { | ||
"springH2ConsoleEnabled": false, | ||
"showSwaggerUILink": false, | ||
"startQtrYYYYQ": null, // use fallback value | ||
"endQtrYYYYQ": null // use fallback value | ||
}); | ||
|
||
render( | ||
<QueryClientProvider client={queryClient}> | ||
<Router > | ||
<UpdateCoursesByQuarterJobForm /> | ||
</Router > | ||
</QueryClientProvider> | ||
); | ||
|
||
// Make sure the first and last options | ||
expect(await screen.findByTestId(/BasicSearch.Quarter-option-0/)).toHaveValue("20211") | ||
expect(await screen.findByTestId(/BasicSearch.Quarter-option-3/)).toHaveValue("20214") | ||
|
||
}); | ||
|
||
|
||
}); |
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.
This should be followed by
// Stryker enable all
after the line of code that does local storage.