Skip to content

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

Merged
merged 11 commits into from
Apr 24, 2024

Conversation

nitzanyiz
Copy link
Collaborator

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 nitzanyiz changed the title SectionWheelPicker Driver to take testID from children SectionWheelPicker driver to accept custom testIDs Feb 12, 2024
@nitzanyiz nitzanyiz assigned nitzanyiz and Inbal-Tish and unassigned nitzanyiz Feb 13, 2024
});
} else {
// Default sections test ids.
sectionsDrivers = React.Children.toArray(driver.getElement().props.children).map((_section, index) => {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

@nitzanyiz
Copy link
Collaborator Author

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

@nitzanyiz nitzanyiz force-pushed the fix/SectionWheelPickerDriver_section_drivers branch from b326468 to 2cc2fd0 Compare March 12, 2024 08:19
@nitzanyiz nitzanyiz requested a review from Inbal-Tish March 12, 2024 08:20
});
});
const sectionsDrivers = React.Children.toArray(driver.getElement().props.children).map((section) => {
if (typeof section === 'object' && 'props' in section) {
Copy link
Collaborator

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?

Copy link
Collaborator Author

@nitzanyiz nitzanyiz Mar 12, 2024

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 nitzanyiz requested a review from Inbal-Tish March 12, 2024 09:47
@Inbal-Tish
Copy link
Collaborator

Inbal-Tish commented Mar 12, 2024

@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

@nitzanyiz
Copy link
Collaborator Author

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 nitzanyiz changed the title SectionWheelPicker driver to accept custom testIDs SectionWheelPicker driver to take testIDs from children Mar 12, 2024
@Inbal-Tish
Copy link
Collaborator

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

@nitzanyiz
Copy link
Collaborator Author

nitzanyiz commented Mar 12, 2024

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

@nitzanyiz nitzanyiz enabled auto-merge (squash) March 28, 2024 07:39
@nitzanyiz nitzanyiz merged commit 579db78 into master Apr 24, 2024
@nitzanyiz nitzanyiz deleted the fix/SectionWheelPickerDriver_section_drivers branch April 24, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants