Unit test for browsing page#2851
Unit test for browsing page#2851shubham-html-css-js wants to merge 3 commits intodistributed-system-analysis:mainfrom
Conversation
|
I don't know why it still says I want to push 30 commits even though all other commits have been merged(I am still learning github),but we have previous commits merged,so you just have to review the latest commit related to unit test |
portante
left a comment
There was a problem hiding this comment.
30 commits for an initial PR might indicate that the starting point was not from the already merged code base in branch main.
Merge conflicts are being reported for this PR, so perhaps we could have it rebased?
dbutenhof
left a comment
There was a problem hiding this comment.
Great start, Shubham! Thanks for working on the unit tests; it's not always as much fun as new features, but it's important!
It sounds like you pushed this PR from a local branch where you'd already been working, without rebasing against main. The rebase should make them go away, so long as they really were merged.
I usually create a new branch from upstream main when starting a PR instead of re-using one; if you reuse, be sure you update your main and rebase first.
| @@ -0,0 +1,30 @@ | |||
| import { Provider } from "react-redux"; | |||
| import store from "store/store"; | |||
| import { MOCK_DATA } from "utils/mockData"; | |||
There was a problem hiding this comment.
This is specifically a mock for /api/v1/datasets/list with specific metadata requested. I think it would be better to give this a more specific name than just "MOCK_DATA", especially with the suggestion that a file named "mockData.js" might provide mocks for other APIs as well?
dashboard/src/modules/components/DatePickerComponent/DatePicker.test.js
Outdated
Show resolved
Hide resolved
dashboard/src/modules/components/SearchComponent/Search.test.js
Outdated
Show resolved
Hide resolved
dashboard/src/modules/components/SearchComponent/Search.test.js
Outdated
Show resolved
Hide resolved
Based on the GitHub "Network" graph on the "Insights" page, it would appear that you created your When you start new work, you should start a new branch, and generally that branch should start from the current end of the Second, you generally should not merge from As for your present situation, there are several ways that you could recover. One would be to reset your branch back prior to the merge from main, and then rebase it, changing the root from If you rename your old branch first, and then create the new branch with the old name, I believe that you'll be able to force-push it to your fork and it will replace the branch there...and the PR will be updated with the result. |
webbnh
left a comment
There was a problem hiding this comment.
Shubham, this is a great start!
However, I'm thinking that this PR should be split: there are a number of pre-cursor changes which are not directly related to unit testing, although they provide features which the unit testing depends on; they should be pulled out into a separate PR which this PR should be based on.
You do a lot of searching for UI elements by various bits of text. These searches seem to be done via case-blind regular expressions containing literal strings. It seems like we should know the exact text, so regular expressions (particularly the case-mapping) shouldn't be necessary. And, it also seems like there should be a more rigorous way of addressing these elements than by picking bits of UI text...but, since that's what the user actually sees, perhaps that's just the thing, but...it seems odd to me.
And, I've got a few other nits, comments, suggestions, and questions.
| useEffect(() => { | ||
| const faviconLogo = document.getElementById("favicon"); | ||
| faviconLogo.setAttribute("href", favicon); | ||
| faviconLogo?.setAttribute("href", favicon); |
There was a problem hiding this comment.
This change doesn't seem like it should be in a unit testing commit/PR.
| @@ -0,0 +1,26 @@ | |||
| import { Provider } from "react-redux"; | |||
| import store from "store/store"; | |||
| import App from "../../../App"; | |||
There was a problem hiding this comment.
In this context, do we have a "root" configured, so that we don't have to use relative import paths? (I.e., can we just import this from "App" or from ./Appbecause the root issrc`?) Ditto for the other modules.
| test("Alert message is displayed on initial load", () => { | ||
| render(<AppWrapper />); | ||
| const alert = screen.getByText(/want to see your own data/i); | ||
| expect(alert).toBeInTheDocument(); |
There was a problem hiding this comment.
Are there any other attributes that we should be checking?
| onChange={(e) => setControllerValue(e)} | ||
| ></TextInput> | ||
| <Button variant="control" onClick={searchController}> | ||
| <Button variant="control" onClick={searchController} aria-label="searchButton"> |
There was a problem hiding this comment.
This doesn't seem like a unit-test-related change.
dashboard/src/modules/components/SearchComponent/Search.test.js
Outdated
Show resolved
Hide resolved
| 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); |
There was a problem hiding this comment.
Can you target them by aria-label value? That seems like a more robust discriminator.
| render(<AppWrapper />); | ||
| await screen.findByText("dhcp1"); | ||
| const datePickerInput = screen.getAllByPlaceholderText(/yyyy-mm-dd/i); | ||
| fireEvent.change(datePickerInput[0], { target: { value: "2022-02-16" } }); |
There was a problem hiding this comment.
Shouldn't we be checking that the UI has updated from YYYY-MM-DD to 2022-02-16?
Also, can the code here look at the values in the React-store? I think those would be good things to check, as well.
dashboard/src/modules/components/HeadingComponent/Heading.test.js
Outdated
Show resolved
Hide resolved
fa14411 to
0f1d0ee
Compare
0f1d0ee to
24dbd85
Compare
dbutenhof
left a comment
There was a problem hiding this comment.
Thanks, Shubham! I can resolve some of my previous conversations, but Webb has some good points/questions and I'd prefer to see a better name for the mocked data.
| @@ -0,0 +1,32 @@ | |||
| export const MOCK_DATA = [ | |||
There was a problem hiding this comment.
I'm still a bit concerned about the generic name MOCK_DATA ... this mocks the response of /datasets/list, but we'll certainly want to have other mocks in the future to test additional parts of the dashboard.
There was a problem hiding this comment.
The /datasets/list response format has changed. There's now a "results" field in the JSON as well as a "next_url" for paging. Also, the dashboard now relies on the resource_id.
{
"next_url": "",
"results": [
{
"metadata": {
"dataset.created": "2022-07-27T15:39:06+00:00"
},
"name": "pbench-user-benchmark_xyz.22_2022.07.27T15.39.06",
"resource_id": "c54ab5929dc6230937402b682751c1ac"
},
{
"metadata": {
"dataset.created": "2022-07-27T15:01:57+00:00"
},
"name": "Short timer",
"resource_id": "8c19617fc80580eaf6bb6808a1f8c46f"
},
{
"metadata": {
"dataset.created": "2022-07-27T13:45:02+00:00"
},
"name": "Soon FOUR",
"resource_id": "4e28f76ccc9572f7e6a27898678db39d"
},
{
"metadata": {
"dataset.created": "2022-07-27T13:45:11+00:00"
},
"name": "Soonish",
"resource_id": "892e506d3302ebaa466b9bc4c02f1780"
},
{
"metadata": {
"dataset.created": "2022-07-20T16:28:32+00:00"
},
"name": "Soon ONE",
"resource_id": "6a4b55f64f8dd5f997be0da70a5e0d2c"
},
{
"metadata": {
"dataset.created": "2022-07-27T13:44:53+00:00"
},
"name": "Soon THREE",
"resource_id": "e368132b16f8a45407c77c0a54a427fb"
}
],
"total": 6
}
|
You need to |
I've come to prefer
I don't know about you, but I've got Git's command line "completer" configured, so I just type a couple of characters and then tab-complete the branch name...so it doesn't matter how long it is. 😉 |
webbnh
left a comment
There was a problem hiding this comment.
It looks like you got the extraneous commits off your branch (yay!), but apparently your branch has conflicts in dashboard/package.json, so it cannot be merged, and the CI tests are refusing to run; so you should address that as soon as possible. (E.g., update your local tracking branch for main, rebase your branch on the end of main again, and resolve the conflicts during the rebase.)
Otherwise, it's just small stuff, but there are some previous comments of mine which you haven't addressed, yet.
| 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(); |
There was a problem hiding this comment.
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...).
expect(screen.queryByText("pbench_user_benchmark1")).toBeInTheDocument();
...
expect(screen.queryByText("pbench_user_benchmark5")).not.toBeInTheDocument();
There was a problem hiding this comment.
A similar comment applies to dashboard/src/modules/components/TableComponent/Table.test.js, and perhaps elsewhere.
| waitFor, | ||
| fireEvent, | ||
| } = require("@testing-library/react"); | ||
| const { render, screen, fireEvent } = require("@testing-library/react"); |
There was a problem hiding this comment.
Teach me something: why do we use require() here instead of import?
| }, [dispatch]); | ||
|
|
||
| const { publicData, favoriteRepoNames } = useSelector( | ||
| const { publicData, favoriteRepoNames,tableData } = useSelector( |
There was a problem hiding this comment.
Looks like you need to run Prettier again. 🙃
It would be good to develop a habit of running Prettier before each commit.
| It will be replaced with the URL of the `public` folder during the build. | ||
| Only files inside the `public` folder can be referenced from the HTML. | ||
|
|
||
There was a problem hiding this comment.
You've got some superfluous blank characters, here.
|
Please consider https://opensource.com/article/20/11/multiple-git-repositories. This gives us all a common way to organize and work together using the same names.
While it is nice to target one branch, it is more often helpful to keep track of everything in
You can also use |
Yup; but I don't use most of those branches routinely, and keeping
Now that I did not know, and that's useful... |
portante
left a comment
There was a problem hiding this comment.
Please update commit log message with Jira issue ID "PBENCH-708".
Configured Package.json to support unit testing without interfering with Patternfly icon import and wrote unit tests for some browsing page components