Skip to content

Commit 2ce3632

Browse files
committed
Changed sections drivers finding
1 parent d0195c5 commit 2ce3632

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed
Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
import _ from 'lodash';
2+
import React from 'react';
23
import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver';
34
import {WheelPickerDriver} from '../WheelPicker/WheelPicker.driver';
45
import {SectionsWheelPickerProps} from './index';
56

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-
});
167

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);
1815

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+
}
1933

20-
return {...driver, sections, sectionsDrivers};
34+
return {...driver, sectionsDrivers};
2135
};

0 commit comments

Comments
 (0)