Skip to content

Commit 51ba1d6

Browse files
authored
Picker - test items exists (Automation gap) (#3724)
1 parent 330eb2f commit 51ba1d6

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/components/picker/Picker.driver.new.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ export const PickerDriver = (props: ComponentProps, useDialog: boolean) => {
6565
}
6666
};
6767

68+
const itemDriver = (testID: string) => ButtonDriver({renderTree: props.renderTree, testID});
69+
6870
const selectItem = (testID: string): void => {
69-
const itemDriver = ButtonDriver({renderTree: props.renderTree, testID});
70-
itemDriver.press();
71+
const driver = itemDriver(testID);
72+
driver.press();
7173
};
7274

7375
return {
@@ -78,6 +80,7 @@ export const PickerDriver = (props: ComponentProps, useDialog: boolean) => {
7880
done,
7981
isOpen,
8082
dismissDialog,
83+
itemDriver,
8184
selectItem
8285
};
8386
};

src/components/picker/__tests__/index.spec.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,58 @@ describe('Picker', () => {
3737
jest.clearAllMocks();
3838
});
3939

40+
describe('Items', () => {
41+
const testItems = [{key: 'one', value: 1, label: 'One', testID: 'item_one'}, {key: 'two', value: 2, label: 'Two', testID: 'item_two'}];
42+
const testItemExists = (TestCase: () => React.JSX.Element) => {
43+
const renderTree = render(<TestCase/>);
44+
const driver = PickerDriver({renderTree, testID}, false);
45+
driver.open();
46+
const item = driver.itemDriver(testItems[0].testID);
47+
expect(item.exists()).toBeTruthy();
48+
};
49+
50+
it('should render picker items when passing children', () => {
51+
const TestCase = () => {
52+
return (
53+
<Picker testID={testID}>
54+
<Picker.Item {...testItems[0]}/>
55+
<Picker.Item {...testItems[1]}/>
56+
</Picker>
57+
);
58+
};
59+
testItemExists(TestCase);
60+
});
61+
62+
it('should render picker items when passing items', () => {
63+
const TestCase = () => {
64+
return (
65+
<Picker testID={testID} items={testItems}/>
66+
);
67+
};
68+
testItemExists(TestCase);
69+
});
70+
71+
it('should render picker items with one option when passing one child', () => {
72+
const TestCase = () => {
73+
return (
74+
<Picker testID={testID}>
75+
<Picker.Item {...testItems[0]}/>
76+
</Picker>
77+
);
78+
};
79+
testItemExists(TestCase);
80+
});
81+
82+
it('should render picker with one option when passing one item', () => {
83+
const TestCase = () => {
84+
return (
85+
<Picker testID={testID} items={[testItems[0]]}/>
86+
);
87+
};
88+
testItemExists(TestCase);
89+
});
90+
});
91+
4092
describe('Modal', () => {
4193
describe('Test open', () => {
4294
it('Should open when enabled', () => {

0 commit comments

Comments
 (0)