Skip to content

[UnderlineNav2]: Increase the unit test coverage - #2506

Merged
broccolinisoup merged 5 commits into
mainfrom
UnderlineNav-testing-improvements
Nov 8, 2022
Merged

[UnderlineNav2]: Increase the unit test coverage#2506
broccolinisoup merged 5 commits into
mainfrom
UnderlineNav-testing-improvements

Conversation

@broccolinisoup

@broccolinisoupbroccolinisoup commented Nov 1, 2022

Copy link
Copy Markdown
Member

Adding unit tests to UnderlineNav

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@changeset-bot

changeset-botBot commented Nov 1, 2022

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 41e17ff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
@primer/reactPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@broccolinisoupbroccolinisoup changed the title UnderlineNav unit tests and snapshot[UnderlineNav2]: Beta standard testingNov 1, 2022
@github-actions

github-actionsBot commented Nov 1, 2022

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
dist/browser.esm.js78.87 KB (0%)
dist/browser.umd.js79.52 KB (0%)

@broccolinisoup
broccolinisoup temporarily deployed to github-pages November 1, 2022 10:34 Inactive
@broccolinisoup
broccolinisoupforce-pushed the UnderlineNav-testing-improvements branch from af846cf to 41ce49eCompareNovember 4, 2022 09:57
@broccolinisoupbroccolinisoup changed the title [UnderlineNav2]: Beta standard testing[UnderlineNav2]: Increase the unit test coverageNov 4, 2022
@broccolinisoup
broccolinisoup marked this pull request as ready for review November 4, 2022 10:03
@broccolinisoup
broccolinisoup temporarily deployed to github-pages November 4, 2022 10:05 Inactive

@joshblackjoshblack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Just had a couple questions around conventions, was curious what your thoughts were 👀

})
it('should move focus to the next/previous item on the list with the tab key', () => {
const {getByText} = render(<ResponsiveUnderlineNav />)
const item = getByText('Code').closest('a') as HTMLAnchorElement

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When do you think it would be better to do getByText('Code').closest('a') versus getByRole('link', { name: 'Code' })

@broccolinisoupbroccolinisoupNov 7, 2022

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Hmm 🤔 I would use them interchangeable but probably not the best. I can't think of any case right now where using the element.closest('a') will be the best, maybe for some reason if we cannot capture the name of the link? Do you have any example? That said, getByRole is more declarative so I'll opt in using this, thank for pointing this out :)

// Focus first item
item.focus()
// Press down arrow
fireEvent.keyDown(item, tab)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When do you think would be best to use fireEvent versus user.tab() from user events? e.g. https://testing-library.com/docs/user-event/convenience/#tab

@broccolinisoupbroccolinisoupNov 7, 2022

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I didn't really know the differences! 😿 Thanks for pointing this out! I got the habit of using fireEvent but I just read about both now and using userEvents makes better sense here because we want to simulate the exact behaviour of user pressing the tab key rather than just firing the actual keydown event. TIL that userEvents might include some other chain of events before the actual keydown fireEvent.

To answer your question, using fireEvent might be a better use probably if we need a different set of chain events before firing the keydown event. For example if we want to test tab key firing without focusing it maybe

@broccolinisoup

Copy link
Copy Markdown
MemberAuthor

@joshblack Thanks so much for your review, great points! I pushed another commit, I'd appreciate if you could have another look. Thanks!

@broccolinisoup
broccolinisoup temporarily deployed to github-pages November 7, 2022 04:29 Inactive
@broccolinisoup
broccolinisoupforce-pushed the UnderlineNav-testing-improvements branch from e06cdc8 to 74b5376CompareNovember 8, 2022 05:06
@broccolinisoup
broccolinisoup temporarily deployed to github-pages November 8, 2022 05:14 Inactive
@broccolinisoup
broccolinisoup temporarily deployed to github-pages November 8, 2022 06:19 Inactive
@broccolinisoup
broccolinisoup merged commit a20faba into mainNov 8, 2022
@broccolinisoup
broccolinisoup deleted the UnderlineNav-testing-improvements branch November 8, 2022 06:21
@primer-cssprimer-css mentioned this pull request Nov 8, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@broccolinisoup@joshblack