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

Coverage #49

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Coverage #49

wants to merge 14 commits into from

Conversation

sirbully
Copy link
Contributor

@sirbully sirbully commented Jul 6, 2024

Resolves #6

What changed 🧐

Please list the changes that are in this PR

  • Modified implementation of some components: Header, LocalToggle, SideDrawer, DrawerContents.
  • Modified implementation of customRender to include userEvent.setup so it does not need to be setup manually in each test case.
  • Fixed vitest configuration and tests setup. I removed unnecessary imports from vitest.
  • Changed to a lower version of jsdom since the heading selector is not working in v24.0.0.
  • Increased test coverage to almost 100%. Not sure how to test routes and the scope of the issue only mentions components so I didn't include it in this PR.
Screenshot 2024-07-06 at 21 20 41

💡 I used getByRole and findByRole a lot in the tests. From react-testing-library docs:

getByRole is the most preferred query to use as it most closely resembles the user experience

How did you test it? 🧪

Please describe new unit tests, E2E tests, or manual testing steps.
Run npm run test.

@sirbully sirbully self-assigned this Jul 6, 2024
@sirbully sirbully requested a review from ann-kilzer as a code owner July 6, 2024 12:29
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to DrawerContents.test.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to SideDrawer.test.tsx

@@ -21,3 +21,5 @@ i18next.use(initReactI18next).init({
// set returnNull to false (and also in the i18next.d.ts options)
// returnNull: false,
});

export default i18next;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Read the docs and they exported this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I think you are right about this, and it solves an issue I faced when I was working on tests. Good find.

});
expect(heading).toBeVisible();

expect(await screen.findAllByRole('heading')).toHaveLength(5);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I lowered jsdom 1 level down since heading was not being recognized as a selector

Copy link
Collaborator

@ann-kilzer ann-kilzer left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look at these changes and identifying a lot of opportunities for improvement.

It's better to keep code reviews small (under 200 LoC is best) and focused around a single change, so I'd like you to divide this into parts and resubmit it:

  • vitest configuration improvements
  • eslint styling changes (Code formatting #51 )
  • adding new tests (may include test file renames)

We can talk about refactoring the components after the tests are in place. (Are you familiar with pindown tests? I didn't look at the commit order) However, I would caution against refactoring too much, unless we have clear reasons. If you'd like to chat or do some pair programming drop me a line.

@@ -1,22 +1,22 @@
import { FC } from 'react'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's separate stylistic changes from logical changes to make the review size smaller.

I noticed recently there is inconsistent semicolon usage. We can talk about whether we want the semi rule on or off, I've heard good arguments for both cases.

const Header: FC = () => {
const theme = useTheme()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not really sure why we are rewriting this. Prefer the original way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, my formatter adds semicolons :orz: will remove these

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here I'm referring to the refactor from lines 9-20

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test coverage could not reach inner = (<MobileHeader />) for some reason so I rewrote it but let me check it again

@@ -1,14 +0,0 @@
import { describe, expect, it } from 'vitest'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this a delete or a rename? Looking now, the title seems redundant.

git mv may be helpful in making the diff show the rename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, after fixing the vitest config, it is now okay not to import describe, expect, it, etc from vitest 🙇‍♀️

@@ -21,3 +21,5 @@ i18next.use(initReactI18next).init({
// set returnNull to false (and also in the i18next.d.ts options)
// returnNull: false,
});

export default i18next;
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a lot of good things you're noticing, though they are out of scope.

Better to have one PR for one task, and keep 'em small 🤏🏻

}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please confirm that you have the .editorconfig plugin installed for your editor: https://editorconfig.org/

(I'll be sure to add this to the readme to make it clearer)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh I might be looking at this backwards... looks like you are following the correct formatting

Comment on lines +13 to +20
const AllTheProviders = ({ children }: React.PropsWithChildren) => {
return (
<CustomThemeProvider>
<CssBaseline />
<MemoryRouter>{children}</MemoryRouter>
</CustomThemeProvider>
);
};
Copy link
Contributor Author

@sirbully sirbully Jul 6, 2024

Choose a reason for hiding this comment

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

moved AllTheProviders inside customRender so there is no need to do // eslint-disable-next-line react-refresh/only-export-components

options?: Omit<RenderOptions, 'wrapper'>,
) => render(ui, { wrapper: AllTheProviders, ...options })
return {
user: userEvent.setup(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added userEvent.setup() here so we don't manually write this in every test case that needs it

Comment on lines -8 to -13
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

used mergeConfig and the config defined in vite.config.ts so we only need to change the vite config in one place and have it reflect here too

@@ -1,4 +1,3 @@
import { describe, expect, it } from 'vitest'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's ok not to import this 👍

@sirbully
Copy link
Contributor Author

sirbully commented Jul 6, 2024

Will resubmit!

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

Successfully merging this pull request may close these issues.

Improve test coverage of unit tests
2 participants