n4kz / react-native-material-dropdown

Material dropdown with consistent behaviour on iOS and Android
Other
734 stars 598 forks source link

Question: How can I assign testID for items? #168

Open duenguyen2103 opened 5 years ago

duenguyen2103 commented 5 years ago

I want to assign the testID label for e2e testing purpose to items. I see this interface in @types/react-native-material-dropdown:

`

export interface DropDownData { / Value of item */ value: string; /* Label to be shown / label?: string; / Props for this item */ props?: Partial; }`

And I've try to do something like this with the hope of assign the testID to items when they show but had no luck. data={[ { value: 'John', props: { testID: 'JohnItem', }, }, { value: 'David', props: { testID: 'DavidItem', }, } ]} Am I wrong about the purpose of the DropDownData.props or using it the wrong way? Is there any other way to apply testID to items?

PaulMest commented 5 years ago

A guy on my team has had difficulty with this, too. We are using Detox for our end-to-end testing, but have not found a workaround for this component yet.

iamclaytonray commented 5 years ago

@duenguyen2103 - it's not a full solution but what I found is that if you scroll to the position you want and do something like handle a tap() event, the tests pass. I don't know what your specific use-case is but I'm assuming it's similar to mine. Unfortunately, only what is visible inside of the dropdown can be tap()'d so this solution isn't the best. AFAIK, there's no API for really handling this (from this lib) so you could do something like calculating the height of the dropdown against the number of items in the list, and the height of each of those items, scrolling to the indexOf() that node and running the rest of your tests from there. Not elegant either, I know 😅

I'm trying to figure out a better solution today. If I figure something out, I'll add a new comment on here with a code example. Probably will dig deeper into the internals here to see if it's something I can get the library to support automatically 🙂

riyga25 commented 5 years ago

I added testID in my fork. Maybe it help somebody