-
Notifications
You must be signed in to change notification settings - Fork 734
SectionWheelPicker driver to take testIDs from children #2949
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
SectionWheelPicker driver to take testIDs from children #2949
Conversation
}); | ||
} else { | ||
// Default sections test ids. | ||
sectionsDrivers = React.Children.toArray(driver.getElement().props.children).map((_section, index) => { |
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.
Why all of this is necessary if you don't check if the child is of type WheelPicker? What's the difference with iterating over driver.getProps().children as SectionsWheelPickerProps
?
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.
Regarding the props. The props that return from getProps are not necessarily SectionsWheelPickerProps they're just the props of the element. (We will probably do something with this function later in the future so I got the props in a different way).
On second look I thinks there might still be a problem here because I'm essentially assuming all the children are WheelPickerSections anyway but thats like the default behavior.
I could change it to always take the testID from the children and hope its a section and not something else we if we ever add anything else there.
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 can check if the child component is of type WheelPickerProps
src/components/sectionsWheelPicker/SectionsWheelPicker.driver.tsx
Outdated
Show resolved
Hide resolved
I think I'll just change it to take the testID from the child component. This will work... |
b326468
to
2cc2fd0
Compare
}); | ||
}); | ||
const sectionsDrivers = React.Children.toArray(driver.getElement().props.children).map((section) => { | ||
if (typeof section === 'object' && 'props' in section) { |
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.
What is this check 'props' in section?
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.
It was needed for TS. React.Children.toArray
return types are unknown or any so it doesn't let me use testID and props.
I changed it to be a little more readable because this is kind of weird in second thought.
@nitzanyiz I am not convinced that this change is necessary. The user is passing the 'section' prop of type WheelPickerProps[] and in SectionsWheelPicker component we are creating the children as WheelPicker elements. Why do we need to check their types? I'm guessing when we need to add a different child we will change the implementation, but I don't see it changing in the near future. |
All the if does is to let me take the testID from the children without typescript errors. I could just add some casting to the children but this does the same thing (trying to just cast the children raises other typescript errors because i'm kind of also setting the ground for when we ditch the getProps with the props typing). |
@nitzanyiz Please try this: return {...driver, sections, sectionsDrivers}; |
This works too although I dont like the casting. I'll just change to that |
Description
In case where custom section are passed with custom testID there is no way for us to understand what is the testID without taking it from the element however I fear that if we use that approach if we ever add some component as a child element in of the SectionWheelPicker we will accidentally also give that element as a section driver. So I added a custom testIDs array that will help us handle custom cases.
Changelog
None
Additional info
None