-
Notifications
You must be signed in to change notification settings - Fork 269
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
Convert remaining components to functional components #464
base: hooks
Are you sure you want to change the base?
Conversation
Co-authored-by: Hrusikesh Panda <[email protected]>
(cherry picked from commit 3cf90bc)
(cherry picked from commit 2701aa2)
…rface (dowjones#434) (cherry picked from commit 3db87c9)
Co-authored-by: Marian Juhas <[email protected]> (cherry picked from commit 2212020)
const keepDropdownActive = useRef(false) | ||
const callbackRef = useRef() | ||
|
||
const setStateWithCallback = (newState, callback) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created it to emulate the callback arg in the old setState
. In the future, this component can be refactored to not need it.
Pull Request Test Coverage Report for Build 1533
💛 - Coveralls |
This is awesome work @m4theushw !! Thanks for sending this. I'm gonna go over it this weekend and having the long weekend helps. This is the first step towards having headless components and I'm glad we're heading in that direction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Findings so far...
@@ -29,7 +29,7 @@ test('some key presses opens dropdown on keyboardNavigation', t => { | |||
;['ArrowUp', 'ArrowDown', 'Home', 'PageUp', 'End', 'PageDown', 'a', 'B'].forEach(key => { | |||
const wrapper = mount(<DropdownTreeSelect data={tree} />) | |||
triggerOnKeyboardKeyDown(wrapper, key) | |||
t.true(wrapper.state().showDropdown) | |||
t.true(wrapper.exists('.dropdown-content')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vaguely remember having this kind of check which wasn't accurately detecting the dropdown state. state.showDropdown
was more trusty as it gets set when the event handler gets called indicating the dropdown is being shown indeed. The only part trust in that case is the CSS properties actually render the div
visible but we don't need to test the browser's CSS engine, so it was an acceptable compromise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could check if the role is "listbox" or "tree". That would be a more recommended approach if React Testing Library was used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. So let's continue with this and tackle it later if we run into similar issues. Maybe moving to RTL could be another PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, dropping enzyme in favor of RTL would be a great improvement in testing quality.
wrapper.find('.search').simulate('click') | ||
t.true(wrapper.exists('.dropdown-content')) | ||
const event = new MouseEvent('click', { bubbles: true, cancelable: true }) | ||
global.document.dispatchEvent(event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting. So with this dispatch, do we still need the simulate('click')
? Seems like they are both asserting the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the simulate('click')
because the old test had it, but it could be removed. The purpose of the dispatch is to ensure that, if the user clicks outside the dropdown, it stays open.
|
||
const searchInput = ( | ||
<Input | ||
ref={searchInputRef} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some problems passing the ref as inputRef
. It seems like AVA can't deal with refs passed through custom named props.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to understand here - don't we do that already? What was the exact error/issue you ran into?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error I got when using inputRef
is:
PointerLookupError {
index: 10,
message: 'Could not deserialize buffer: pointer 10 could not be resolved',
}
I found this relatated issue. I tried to upgrade AVA to the latest version but it didn't solve the problem.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions. |
What does it do?
Checklist: