Skip to content

Commit fa14411

Browse files
author
shubhamBansal
committed
Controller notion removed from test cases and support for coverage added
1 parent 739e5dc commit fa14411

File tree

13 files changed

+201
-298
lines changed

13 files changed

+201
-298
lines changed

dashboard/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"classnames": "^2.3.1",
1616
"crypto-js": "^4.1.1",
1717
"js-cookie": "^3.0.1",
18+
"babel-jest": "^27.5.1",
19+
"gulp": "^4.0.2",
20+
"jest": "^27.5.1",
1821
"less-watch-compiler": "^1.16.3",
1922
"patternfly": "^3.9.0",
2023
"react": "^17.0.2",
@@ -34,7 +37,7 @@
3437
"scripts": {
3538
"start": "react-scripts start",
3639
"build": "react-scripts build",
37-
"test": "react-scripts test",
40+
"test": "react-scripts test --coverage",
3841
"eject": "react-scripts eject"
3942
},
4043
"jest":{

dashboard/src/modules/components/DatePickerComponent/DatePicker.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,26 @@ jest.mock("utils/api", () => {
1414
return {
1515
get: () => ({
1616
data: MOCK_DATA,
17+
status:200
1718
}),
1819
};
1920
});
2021
test("data is filtered based on date range selected from date picker", async () => {
2122
render(<AppWrapper />);
22-
await screen.findByText("dhcp1");
23+
await screen.findByText("pbench_user_benchmark1");
2324
const datePickerInput = screen.getAllByPlaceholderText(/yyyy-mm-dd/i);
2425
fireEvent.change(datePickerInput[0], { target: { value: "2022-02-16" } });
2526
fireEvent.change(datePickerInput[1], { target: { value: "2022-02-20" } });
2627
const updateBtn = screen.getByRole("button", { name: /update/i });
2728
fireEvent.click(updateBtn);
28-
const cells = screen.getAllByRole("cell");
29-
expect(cells).toHaveLength(12);
29+
const datasetNameOne = screen.queryByText("pbench_user_benchmark1");
30+
const datasetNameTwo = screen.queryByText("pbench_user_benchmark2");
31+
const datasetNameThree = screen.queryByText("pbench_user_benchmark3");
32+
const datasetNameFour = screen.queryByText("pbench_user_benchmark4");
33+
const datasetNameFive = screen.queryByText("pbench_user_benchmark5");
34+
expect(datasetNameOne).toBeInTheDocument();
35+
expect(datasetNameTwo).toBeInTheDocument();
36+
expect(datasetNameThree).toBeInTheDocument();
37+
expect(datasetNameFour).not.toBeInTheDocument();
38+
expect(datasetNameFive).not.toBeInTheDocument();
3039
});

dashboard/src/modules/components/EmptyStateComponent/index.jsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

dashboard/src/modules/components/HeadingComponent/Heading.test.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

dashboard/src/modules/components/HeadingComponent/index.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

dashboard/src/modules/components/HeadingComponent/index.jsx

Lines changed: 0 additions & 18 deletions
This file was deleted.

dashboard/src/modules/components/SearchComponent/Search.test.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

dashboard/src/modules/components/SearchComponent/index.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

dashboard/src/modules/components/SearchComponent/index.jsx

Lines changed: 0 additions & 32 deletions
This file was deleted.

dashboard/src/modules/components/TableComponent/Table.test.js

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { Provider } from "react-redux";
22
import store from "store/store";
33
import { MOCK_DATA } from "utils/mockData";
44
import App from "../../../App";
5-
const {
6-
render,
7-
screen,
8-
waitFor,
9-
fireEvent,
10-
} = require("@testing-library/react");
5+
const { render, screen, fireEvent } = require("@testing-library/react");
116
const AppWrapper = () => {
127
return (
138
<Provider store={store}>
@@ -19,21 +14,34 @@ jest.mock("utils/api", () => {
1914
return {
2015
get: () => ({
2116
data: MOCK_DATA,
17+
status: 200,
2218
}),
2319
};
2420
});
25-
21+
test("Page heading is displayed on initial load", async () => {
22+
render(<AppWrapper />);
23+
await screen.findByText("pbench_user_benchmark1");
24+
const heading = screen.getByRole("heading", { name: /results/i });
25+
expect(heading).toBeInTheDocument();
26+
});
2627
test("data from API is displayed on initial load", async () => {
2728
render(<AppWrapper />);
28-
const benchmarkName = await screen.findByText("pbench_user_benchmark1");
29-
const cells = await screen.findAllByRole("cell");
30-
await waitFor(() => expect(benchmarkName).toBeInTheDocument());
31-
await waitFor(() => expect(cells).toHaveLength(20));
29+
await screen.findByText("pbench_user_benchmark1");
30+
const datasetNameOne = screen.queryByText("pbench_user_benchmark1");
31+
const datasetNameTwo = screen.queryByText("pbench_user_benchmark2");
32+
const datasetNameThree = screen.queryByText("pbench_user_benchmark3");
33+
const datasetNameFour = screen.queryByText("pbench_user_benchmark4");
34+
const datasetNameFive = screen.queryByText("pbench_user_benchmark5");
35+
expect(datasetNameOne).toBeInTheDocument();
36+
expect(datasetNameTwo).toBeInTheDocument();
37+
expect(datasetNameThree).toBeInTheDocument();
38+
expect(datasetNameFour).toBeInTheDocument();
39+
expect(datasetNameFive).toBeInTheDocument();
3240
});
3341

3442
test("row is favorited after clicking on favorite icon", async () => {
3543
render(<AppWrapper />);
36-
await screen.findByText("dhcp1");
44+
await screen.findByText("pbench_user_benchmark1");
3745
const starBtn = screen.getAllByRole("button", {
3846
name: /not starred/i,
3947
});
@@ -43,6 +51,28 @@ test("row is favorited after clicking on favorite icon", async () => {
4351
name: /see favorites button/i,
4452
});
4553
fireEvent.click(favoriteBtn);
46-
const favoriteCell = screen.getAllByRole("cell");
47-
expect(favoriteCell).toHaveLength(8);
54+
const datasetNameOne = screen.queryByText("pbench_user_benchmark1");
55+
const datasetNameTwo = screen.queryByText("pbench_user_benchmark2");
56+
const datasetNameThree = screen.queryByText("pbench_user_benchmark3");
57+
const datasetNameFour = screen.queryByText("pbench_user_benchmark4");
58+
const datasetNameFive = screen.queryByText("pbench_user_benchmark5");
59+
expect(datasetNameOne).toBeInTheDocument();
60+
expect(datasetNameTwo).toBeInTheDocument();
61+
expect(datasetNameThree).not.toBeInTheDocument();
62+
expect(datasetNameFour).not.toBeInTheDocument();
63+
expect(datasetNameFive).not.toBeInTheDocument();
64+
});
65+
test("data is filtered based on value in search box", async () => {
66+
render(<AppWrapper />);
67+
await screen.findByText("pbench_user_benchmark1");
68+
const searchBox = screen.getByPlaceholderText(/search dataset/i);
69+
fireEvent.change(searchBox, { target: { value: "pbench_user_benchmark2" } });
70+
const searchBtn = screen.getByRole("button", {
71+
name: /searchButton/i,
72+
});
73+
fireEvent.click(searchBtn);
74+
const datasetNameTwo = screen.queryByText("pbench_user_benchmark2");
75+
const datasetNameThree = screen.queryByText("pbench_user_benchmark3");
76+
expect(datasetNameTwo).toBeInTheDocument();
77+
expect(datasetNameThree).not.toBeInTheDocument();
4878
});

0 commit comments

Comments
 (0)