|
1 | 1 | import _ from 'lodash';
|
| 2 | +import React from 'react'; |
2 | 3 | import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver';
|
3 | 4 | import {WheelPickerDriver} from '../WheelPicker/WheelPicker.driver';
|
4 | 5 | import {SectionsWheelPickerProps} from './index';
|
5 | 6 |
|
6 |
| -export const SectionsWheelPickerDriver = (props: ComponentProps) => { |
7 |
| - const driver = useComponentDriver<SectionsWheelPickerProps>(props); |
8 |
| - const sections = driver.getProps().children as SectionsWheelPickerProps; |
9 |
| - const sectionsDrivers = _.map(sections, (_, index) => { |
10 |
| - const sectionTestID = `${props.testID}.${index}`; |
11 |
| - return WheelPickerDriver({ |
12 |
| - renderTree: props.renderTree, |
13 |
| - testID: sectionTestID |
14 |
| - }); |
15 |
| - }); |
16 | 7 |
|
17 |
| - |
| 8 | +type CustomSectionsTestIds = { |
| 9 | + customSectionTestIds?: string[] |
| 10 | +}; |
| 11 | + |
| 12 | +export const SectionsWheelPickerDriver = (props: ComponentProps & CustomSectionsTestIds) => { |
| 13 | + const {customSectionTestIds, ...others} = props; |
| 14 | + const driver = useComponentDriver<SectionsWheelPickerProps>(others); |
18 | 15 |
|
| 16 | + let sectionsDrivers: (ReturnType<typeof WheelPickerDriver>)[]; |
| 17 | + if (customSectionTestIds) { |
| 18 | + sectionsDrivers = customSectionTestIds.map(item => { |
| 19 | + return WheelPickerDriver({ |
| 20 | + renderTree: props.renderTree, |
| 21 | + testID: `${props.testID}.${item}` |
| 22 | + }); |
| 23 | + }); |
| 24 | + } else { |
| 25 | + // Default sections test ids. |
| 26 | + sectionsDrivers = React.Children.toArray(driver.getElement().props.children).map((_section, index) => { |
| 27 | + return WheelPickerDriver({ |
| 28 | + renderTree: props.renderTree, |
| 29 | + testID: `${props.testID}.${index}` |
| 30 | + }); |
| 31 | + }); |
| 32 | + } |
19 | 33 |
|
20 |
| - return {...driver, sections, sectionsDrivers}; |
| 34 | + return {...driver, sectionsDrivers}; |
21 | 35 | };
|
0 commit comments