react-native-ui-lib icon indicating copy to clipboard operation
react-native-ui-lib copied to clipboard

SectionWheelPicker driver to take testIDs from children

Open nitzanyiz opened this issue 2 years ago • 5 comments

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

nitzanyiz avatar Feb 12 '24 11:02 nitzanyiz

I think I'll just change it to take the testID from the child component. This will work...

nitzanyiz avatar Feb 15 '24 08:02 nitzanyiz

@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

Inbal-Tish avatar Mar 12 '24 10:03 Inbal-Tish

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 avatar Mar 12 '24 11:03 nitzanyiz

@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}; };`

Inbal-Tish avatar Mar 12 '24 11:03 Inbal-Tish

This works too although I dont like the casting. I'll just change to that

nitzanyiz avatar Mar 12 '24 11:03 nitzanyiz