Skip to content
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

Week 2 tests #233

Merged
merged 10 commits into from Aug 9, 2021
Merged

Week 2 tests #233

merged 10 commits into from Aug 9, 2021

Conversation

Eddges
Copy link
Contributor

@Eddges Eddges commented Jul 19, 2021

I have modified the Sidebar.js component to make use of useRouter() from next/router. There were some bugs I faced on simulating click interaction. On reading about the issues, I came to know that next/link component that we use currently has some bugs and is not a great API, having inconsistencies in its implementation.

References:
vercel/next.js#16864 (comment)
vercel/next.js#1490 (comment)

@sarathms
Copy link
Contributor

I am yet to checkout this branch and run the app. But one thing I would like to point out is that not using next/link and treating them as regular <a> links may have some impact on how the app handles page transitions. It may or may not be applicable to the way we use <Link> in our app. E.g In some cases, clicking <Link> only causes client-side changes without a full page reload starting with blank white page.

@Eddges
Copy link
Contributor Author

Eddges commented Jul 22, 2021

I understand. I've actually replaced Link with Flex from ooni-components which I think is a regular div tag. I have passed an onClick listener to it.

Copy link
Contributor

@sarathms sarathms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have left a few suggestions as inline comments to improve some of the tests.

I would encourage to avoid writing tests where the only assertion is expect(text).toBeInTheDocument() especially where text is not a result of a specific DOM query. For example the Sidebar test for version number. Feel free to sprinkle as many data-testids as you want and use them to query in such simple tests.

renderComponent(
<NavItem
key={idx}
pathName="/dashboard"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is /dashboard hard coded here?

expect(screen.getByText('Test paragraph')).toBeInTheDocument()
})

test('NavItem renders Navigation List correctly in the Sidebar', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not directly test by rendering <Sidebar> and checking if it has all the items in navigationPath and if each of them navigates to the right page?

const runButton = screen.getByText(English['Dashboard.Overview.Run'])
expect(runButton).toBeInTheDocument()
fireEvent.click(runButton)
expect(onRunTest).toHaveBeenCalledTimes(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are only testing if the callback was called, then we should be testing the hook useRunTest also.

jest.clearAllMocks()
})

test('All the Test Cards are mounted', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is relevant only if we are testing by rendering pages/dashboard/index.js and checking if all there are cards for each item in testList. Otherwise we are manually mounting all the cards in the test setup itself.

/>
)

const testCard = screen.getByTestId('card')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test if testCard has visible content that matches what's in websiteDetails

@Eddges
Copy link
Contributor Author

Eddges commented Jul 30, 2021

I have removed some tests which I felt were not relevant at all. I have only kept the ones which I felt added confidence in the component.

Copy link
Contributor

@sarathms sarathms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I think this is good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants