-
Notifications
You must be signed in to change notification settings - Fork 108
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
Unit test for browsing page #2851
base: main
Are you sure you want to change the base?
Changes from 2 commits
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 |
---|---|---|
|
@@ -14,17 +14,26 @@ jest.mock("utils/api", () => { | |
return { | ||
get: () => ({ | ||
data: MOCK_DATA, | ||
status:200 | ||
}), | ||
}; | ||
}); | ||
test("data is filtered based on date range selected from date picker", async () => { | ||
render(<AppWrapper />); | ||
await screen.findByText("dhcp1"); | ||
const datePickerInput = screen.getAllByPlaceholderText(/yyyy-mm-dd/i); | ||
await screen.findByText("pbench_user_benchmark1"); | ||
const datePickerInput = screen.getAllByPlaceholderText('YYYY-MM-DD'); | ||
fireEvent.change(datePickerInput[0], { target: { value: "2022-02-16" } }); | ||
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. Shouldn't we be checking that the UI has updated from Also, can the code here look at the values in the React-store? I think those would be good things to check, as well. |
||
fireEvent.change(datePickerInput[1], { target: { value: "2022-02-20" } }); | ||
const updateBtn = screen.getByRole("button", { name: /update/i }); | ||
const updateBtn = screen.getByRole("button", { name: 'Update'}); | ||
fireEvent.click(updateBtn); | ||
const cells = screen.getAllByRole("cell"); | ||
expect(cells).toHaveLength(12); | ||
const datasetNameOne = screen.queryByText("pbench_user_benchmark1"); | ||
const datasetNameTwo = screen.queryByText("pbench_user_benchmark2"); | ||
const datasetNameThree = screen.queryByText("pbench_user_benchmark3"); | ||
const datasetNameFour = screen.queryByText("pbench_user_benchmark4"); | ||
const datasetNameFive = screen.queryByText("pbench_user_benchmark5"); | ||
expect(datasetNameOne).toBeInTheDocument(); | ||
expect(datasetNameTwo).toBeInTheDocument(); | ||
expect(datasetNameThree).toBeInTheDocument(); | ||
expect(datasetNameFour).not.toBeInTheDocument(); | ||
expect(datasetNameFive).not.toBeInTheDocument(); | ||
Comment on lines
+29
to
+38
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. It looks to me like these assertions will fit on one line, so there's no need to use local variables for them (in-lining the expressions will cut the number of new lines of code in half...).
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. A similar comment applies to |
||
}); |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,7 @@ import { Provider } from "react-redux"; | |
import store from "store/store"; | ||
import { MOCK_DATA } from "utils/mockData"; | ||
import App from "../../../App"; | ||
const { | ||
render, | ||
screen, | ||
waitFor, | ||
fireEvent, | ||
} = require("@testing-library/react"); | ||
const { render, screen, fireEvent } = require("@testing-library/react"); | ||
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. Teach me something: why do we use |
||
const AppWrapper = () => { | ||
return ( | ||
<Provider store={store}> | ||
|
@@ -19,30 +14,65 @@ jest.mock("utils/api", () => { | |
return { | ||
get: () => ({ | ||
data: MOCK_DATA, | ||
status: 200, | ||
}), | ||
}; | ||
}); | ||
|
||
test("Page heading is displayed on initial load", async () => { | ||
render(<AppWrapper />); | ||
await screen.findByText("pbench_user_benchmark1"); | ||
const heading = screen.getByRole("heading", { name: 'Results' }); | ||
expect(heading).toBeInTheDocument(); | ||
}); | ||
test("data from API is displayed on initial load", async () => { | ||
render(<AppWrapper />); | ||
const benchmarkName = await screen.findByText("pbench_user_benchmark1"); | ||
const cells = await screen.findAllByRole("cell"); | ||
await waitFor(() => expect(benchmarkName).toBeInTheDocument()); | ||
await waitFor(() => expect(cells).toHaveLength(20)); | ||
await screen.findByText("pbench_user_benchmark1"); | ||
const datasetNameOne = screen.queryByText("pbench_user_benchmark1"); | ||
const datasetNameTwo = screen.queryByText("pbench_user_benchmark2"); | ||
const datasetNameThree = screen.queryByText("pbench_user_benchmark3"); | ||
const datasetNameFour = screen.queryByText("pbench_user_benchmark4"); | ||
const datasetNameFive = screen.queryByText("pbench_user_benchmark5"); | ||
expect(datasetNameOne).toBeInTheDocument(); | ||
expect(datasetNameTwo).toBeInTheDocument(); | ||
expect(datasetNameThree).toBeInTheDocument(); | ||
expect(datasetNameFour).toBeInTheDocument(); | ||
expect(datasetNameFive).toBeInTheDocument(); | ||
}); | ||
|
||
test("row is favorited after clicking on favorite icon", async () => { | ||
render(<AppWrapper />); | ||
await screen.findByText("dhcp1"); | ||
await screen.findByText("pbench_user_benchmark1"); | ||
const starBtn = screen.getAllByRole("button", { | ||
name: /not starred/i, | ||
name: 'Not starred', | ||
}); | ||
fireEvent.click(starBtn[0]); | ||
fireEvent.click(starBtn[1]); | ||
const favoriteBtn = screen.getByRole("button", { | ||
name: /see favorites button/i, | ||
name: 'see favorites button', | ||
}); | ||
fireEvent.click(favoriteBtn); | ||
const favoriteCell = screen.getAllByRole("cell"); | ||
expect(favoriteCell).toHaveLength(8); | ||
const datasetNameOne = screen.queryByText("pbench_user_benchmark1"); | ||
const datasetNameTwo = screen.queryByText("pbench_user_benchmark2"); | ||
const datasetNameThree = screen.queryByText("pbench_user_benchmark3"); | ||
const datasetNameFour = screen.queryByText("pbench_user_benchmark4"); | ||
const datasetNameFive = screen.queryByText("pbench_user_benchmark5"); | ||
expect(datasetNameOne).toBeInTheDocument(); | ||
expect(datasetNameTwo).toBeInTheDocument(); | ||
expect(datasetNameThree).not.toBeInTheDocument(); | ||
expect(datasetNameFour).not.toBeInTheDocument(); | ||
expect(datasetNameFive).not.toBeInTheDocument(); | ||
}); | ||
test("data is filtered based on value in search box", async () => { | ||
render(<AppWrapper />); | ||
await screen.findByText("pbench_user_benchmark1"); | ||
const searchBox = screen.getByPlaceholderText('Search Dataset'); | ||
fireEvent.change(searchBox, { target: { value: "pbench_user_benchmark2" } }); | ||
webbnh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const searchBtn = screen.getByRole("button", { | ||
name: 'searchButton', | ||
}); | ||
fireEvent.click(searchBtn); | ||
const datasetNameTwo = screen.queryByText("pbench_user_benchmark2"); | ||
const datasetNameThree = screen.queryByText("pbench_user_benchmark3"); | ||
expect(datasetNameTwo).toBeInTheDocument(); | ||
expect(datasetNameThree).not.toBeInTheDocument(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,11 +26,11 @@ import DatePickerWidget from "../DatePickerComponent"; | |
import PathBreadCrumb from "../BreadCrumbComponent"; | ||
import { LoginHint, Heading, EmptyTable, SearchBox } from "./common-components"; | ||
import { getTodayMidnightUTCDate } from "utils/dateFunctions"; | ||
import { bumpToDate } from "utils/dateFunctions"; | ||
|
||
let startDate = new Date(Date.UTC(1990, 10, 4)); | ||
let endDate = getTodayMidnightUTCDate(); | ||
let endDate = bumpToDate(getTodayMidnightUTCDate(),1); | ||
let datasetName = ""; | ||
let dataArray = []; | ||
|
||
const TableWithFavorite = () => { | ||
const columnNames = { | ||
|
@@ -51,7 +51,7 @@ const TableWithFavorite = () => { | |
dispatch(getFavoritedDatasets()); | ||
}, [dispatch]); | ||
|
||
const { publicData, favoriteRepoNames } = useSelector( | ||
const { publicData, favoriteRepoNames,tableData } = useSelector( | ||
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. Looks like you need to run Prettier again. 🙃 It would be good to develop a habit of running Prettier before each commit. |
||
(state) => state.datasetlist | ||
); | ||
const setPublicData = (data) => { | ||
|
@@ -141,20 +141,17 @@ const TableWithFavorite = () => { | |
|
||
<PageSection variant={PageSectionVariants.light}> | ||
<PathBreadCrumb pathList={datasetBreadcrumb} /> | ||
<Heading | ||
containerClass="publicDataPageTitle" | ||
headingTitle="Results" | ||
/> | ||
<Heading containerClass="publicDataPageTitle" headingTitle="Results" /> | ||
<div className="filterContainer"> | ||
<SearchBox | ||
dataArray={dataArray} | ||
dataArray={tableData} | ||
setPublicData={setPublicData} | ||
startDate={startDate} | ||
endDate={endDate} | ||
setDatasetName={setDatasetName} | ||
/> | ||
<DatePickerWidget | ||
dataArray={dataArray} | ||
dataArray={tableData} | ||
setPublicData={setPublicData} | ||
datasetName={datasetName} | ||
setDateRange={setDateRange} | ||
|
@@ -167,13 +164,15 @@ const TableWithFavorite = () => { | |
isSelected={isSelected === "datasetListButton"} | ||
onChange={handleButtonClick} | ||
className="datasetListButton" | ||
aria-label="see dataset button" | ||
/> | ||
<ToggleGroupItem | ||
text={`Favorites(${favoriteRepoNames?.length})`} | ||
buttonId="favoriteListButton" | ||
isSelected={isSelected === "favoriteListButton"} | ||
onChange={handleButtonClick} | ||
className="favoriteListButton" | ||
aria-label="see favorites button" | ||
/> | ||
</ToggleGroup> | ||
<TableComposable aria-label="Favoritable table" variant="compact"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,29 @@ | ||
export const MOCK_DATA = [ | ||
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. I'm still a bit concerned about the generic name 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. The
|
||
{ | ||
controller: "dhcp1", | ||
name: "pbench_user_benchmark1", | ||
metadata: { | ||
"dataset.created": "2022-02-16T13:21:29+00:00", | ||
}, | ||
}, | ||
{ | ||
controller: "dhcp2", | ||
name: "pbench_user_benchmark2", | ||
metadata: { | ||
"dataset.created": "2022-02-18T13:21:29+00:00", | ||
}, | ||
}, | ||
{ | ||
controller: "dhcp3", | ||
name: "pbench_user_benchmark3", | ||
metadata: { | ||
"dataset.created": "2022-02-20T13:21:29+00:00", | ||
}, | ||
}, | ||
{ | ||
controller: "dhcp4", | ||
name: "pbench_user_benchmark4", | ||
metadata: { | ||
"dataset.created": "2022-02-25T13:21:29+00:00", | ||
}, | ||
}, | ||
{ | ||
controller: "dhcp5", | ||
name: "pbench_user_benchmark5", | ||
metadata: { | ||
"dataset.created": "2022-03-08T13:21:29+00:00", | ||
|
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.
Are there any other attributes that we should be checking?