Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

test(Dropdown): add more unit tests#1201

Merged
silviuaavram merged 20 commits intomasterfrom
chore-add-dropdown-tests
Apr 15, 2019
Merged

test(Dropdown): add more unit tests#1201
silviuaavram merged 20 commits intomasterfrom
chore-add-dropdown-tests

Conversation

@silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Apr 10, 2019

I did not follow any test plan, we don't have any. There are tests for basic things, like highlightedIndex, open, value and some props like highlightFirstItemOnOpen or moveFocusOnTab.

There are many more to be added, but this one is already a biggie. Will put it for review like this and will add others in a separate PR.

Did not manage to test:

  1. open dropdown by Space or Enter. Dropdown does not open.
  2. test moveFocusOnTab. Focus is not handled when using Tab. We can check if selection is performed but not where the focus is.

@silviuaavram silviuaavram changed the title chore: add dropdown unit tests chore(dropdown): add more unit tests Apr 10, 2019
@DustyTheBot
Copy link
Collaborator

Warnings
⚠️ There are no updates provided to CHANGELOG. Ensure there are no publicly visible changes introduced by this PR.

Generated by 🚫 dangerJS

@codecov
Copy link

codecov bot commented Apr 10, 2019

Codecov Report

Merging #1201 into master will increase coverage by 0.67%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1201      +/-   ##
==========================================
+ Coverage   82.53%   83.21%   +0.67%     
==========================================
  Files         751      751              
  Lines        8881     8881              
  Branches     1260     1260              
==========================================
+ Hits         7330     7390      +60     
+ Misses       1536     1477      -59     
+ Partials       15       14       -1
Impacted Files Coverage Δ
...t/src/components/Dropdown/DropdownSelectedItem.tsx 76.59% <0%> (+2.12%) ⬆️
packages/react/src/components/Layout/Layout.tsx 98.21% <0%> (+3.57%) ⬆️
...ackages/react/src/components/Dropdown/Dropdown.tsx 76.4% <0%> (+15.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5affb1...b7bd5e2. Read the comment docs.

expect(onSelectedChange).toHaveBeenLastCalledWith(
null,
expect.objectContaining({
value: items[itemSelectedIndex],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
value: items[itemSelectedIndex],
value: 'item2',

Nit: It's more human readable

const triggerButton = wrapper.find(`button.${Dropdown.slotClassNames.triggerButton}`)

triggerButton
.simulate('click')
Copy link
Contributor

@mnajdova mnajdova Apr 12, 2019

Choose a reason for hiding this comment

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

Shouldn't we first navigate to the list items by arrow down and then press escape? Otherwise we are laying about what the test is checking..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we are already checking that on trigger click, the focus goes to the list, it's a test called 'opens the menu and moves focus to list in selection mode'

so assuming this works, the focus is already in the list, and we hit Escape to close it.

@layershifter layershifter changed the title chore(dropdown): add more unit tests test(dropdown): add more unit tests Apr 15, 2019
onOpenChange.mockReset()
})

it('is false when closed by trigger button click', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it('is false when closed by trigger button click', () => {
it('is "false" when closed by trigger button click', () => {

NIT

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will change here and for next tests as well thanks!

open: false,
}),
)
})
Copy link
Member

Choose a reason for hiding this comment

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

expect(onOpenChange).toHaveBeenLastCalledWithMatch(null, { open: false })

Not related to this PR, but I suggest to introduce a custom matcher for these cases (6 lines vs 1)...

)
})

it('has multiple items at multiple selections if the multiple prop is supplied', () => {
Copy link
Member

Choose a reason for hiding this comment

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

I don't have a suggestion there, but there are definitely too many multiple 🐱

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah ...

expect(onSelectedChange).toHaveBeenLastCalledWith(
null,
expect.objectContaining({
value: [items[indexesOfItemsSelected[0]], items[indexesOfItemsSelected[1] + 1]],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
value: [items[indexesOfItemsSelected[0]], items[indexesOfItemsSelected[1] + 1]],
value: [items[1], items[4]],

Can we use constant values there? It's very hard to read...

Copy link
Member

Choose a reason for hiding this comment

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

searchInput
.simulate('click')
.simulate('change', { target: { value: 'test' } })
.simulate('keydown', { keyCode: keyboardKey.Escape, key: 'Escape' })
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR:
It's strange to me that we should pass key always for Downshift: https://github.com/downshift-js/downshift/blob/8f987928e6a0ff4d0d9e6259748bcd243532f0ec/src/utils.js#L252

It will be great to reuse keyboard-key there an simplify it...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will try to take a look in a future PR.

@layershifter layershifter changed the title test(dropdown): add more unit tests test(Dropdown): add more unit tests Apr 15, 2019
Copy link
Member

@layershifter layershifter left a comment

Choose a reason for hiding this comment

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

Please take a look on comments before merge 💃

@silviuaavram silviuaavram merged commit 0089939 into master Apr 15, 2019
@delete-merged-branch delete-merged-branch bot deleted the chore-add-dropdown-tests branch April 15, 2019 14:36
@kuzhelov kuzhelov mentioned this pull request Jun 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants