SectionWheelPicker driver to take testIDs from children
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
I think I'll just change it to take the testID from the child component. This will work...
@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.
Seems to me the only change needed is to get the testID from the section instead of creating a new one. Something like:
testID: section?.testID || sectionTestID
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:
export const SectionsWheelPickerDriver = (props: ComponentProps) => { const driver = useComponentDriver<SectionsWheelPickerProps>(props); const sections = driver.getElement()?.props?.children as SectionsWheelPickerProps['sections']; const sectionsDrivers = _.map(sections, (section, index) => { const sectionTestID = ${props.testID}.${index}`;
return WheelPickerDriver({
renderTree: props.renderTree,
testID: section?.testID || sectionTestID
});
});
return {...driver, sections, sectionsDrivers}; };`
This works too although I dont like the casting. I'll just change to that