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

fix(Dropdown): reset highlighted index on input change #1168

Merged
merged 13 commits into from
Apr 8, 2019

Conversation

silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Apr 4, 2019

This should reset the highlightedIndex to null or 0, depending whether highlightFirstItemOnOpen has been passed or not.

@codecov
Copy link

codecov bot commented Apr 4, 2019

Codecov Report

Merging #1168 into master will increase coverage by 0.11%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1168      +/-   ##
==========================================
+ Coverage   82.36%   82.48%   +0.11%     
==========================================
  Files         733      733              
  Lines        8716     8717       +1     
  Branches     1165     1232      +67     
==========================================
+ Hits         7179     7190      +11     
+ Misses       1522     1511      -11     
- Partials       15       16       +1
Impacted Files Coverage Δ
...ackages/react/src/components/Dropdown/Dropdown.tsx 61.29% <100%> (+2.79%) ⬆️

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 5835d10...5ff41cc. Read the comment docs.

@@ -57,7 +58,7 @@ describe('Dropdown', () => {
)
})

it('calls onOpen with highlightedIndex + 1 on arrow down', () => {
it('has the provided prop value + 1 when opened by ArrowDown', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

just for the sake of better clarity, lets use braces:

has value of (provided prop value + 1) when opened by ArrowDown

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, good idea!

@@ -77,7 +78,7 @@ describe('Dropdown', () => {
)
})

it('calls onOpen with highlightedIndex - 1 on arrow down', () => {
it('has the provided prop value - 1 when opened by ArrowUp', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: lets try to avoid the terminology that is code specific, like ArrowUp - we might better use implementation-agnostic arrow up key

@@ -137,7 +138,7 @@ describe('Dropdown', () => {
)
})

it('calls onOpen with highlightedIndex set to defaultHighlightedIndex', () => {
it('is defaultHighlightedIndex value at first opening', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit-nit: just to be on par with the naming used fo rother test cases, lets add prop word, to better describe origin of defaultHighlightedIndex:

is defaultHighlightedIndex prop value at first opening

@@ -156,11 +157,24 @@ describe('Dropdown', () => {
open: true,
}),
)

wrapper
Copy link
Contributor

Choose a reason for hiding this comment

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

actually, its not easy to see the reason for the event to happen this amount of times (which is requested by test). Could you, please, suggest why onOpenChange fires twice for each click?

Copy link
Contributor

Choose a reason for hiding this comment

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

also, this check, apparently, verifies that on the subsequent open events defaultHighlightedIndex value is not honored. I would suggest to extract this check to the dedicated test case, with the corresponding name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

well, it is 3 because it opened a couple of times and closed once.

I just want to make sure that on opening it the second time, it opens and there is no item highlighted.

what do you think I should change?

Copy link
Contributor

Choose a reason for hiding this comment

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

got it - I think that it would be more apparent if you would introduce a separate test case for that, the one that would follow a plan like:

  • do whatever is necessary to prepare test state (arrange + act)
  • verify conditions (assert)

Specifically to this example, it could be done the following way:

  • introduce test case with a name like is not set on second and subsequent openings
  • do the arrangement once there
wrapper
  .find(...)
  . ...
  .simulate('click')
  .expect( .. ) // and this is where assertion phase starts

If there will be just single arrangement phase followed by assertion, it would be much easier to infer where the numbers come from :) currently the main problem is that there are several such phases within single test, so that the side effect of the previous arrangement affects the following one, which is not intuitive and harder to maintain

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

split the test into two.

@@ -183,6 +197,95 @@ describe('Dropdown', () => {
}),
)
})

it('is set to 0 at searchQuery change and when highlightFirstItemOnOpen prop is provided', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: at -> on:

is set to 0 on searchQuery change and when highlightFirstItemOnOpen prop is provided

Copy link
Contributor

@kuzhelov kuzhelov left a comment

Choose a reason for hiding this comment

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

agree with the changes - could you, please, take a look on the comments for the tests part, to clarify couple of moments for me? Thank you!

@silviuaavram silviuaavram merged commit 6adb950 into master Apr 8, 2019
@silviuaavram silviuaavram deleted the fix-highlighted-index-on-input-change branch April 8, 2019 10:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants