Skip to content

Commit 78a3ea1

Browse files
authored
Button tests with test kit (#1785)
* Add testKit for Text, Image, Button. Add tests for Button * export testkits * lint fix * update snapshot * change variable names * review fixes * add tests for Text component using TextTestKit * fix lint
1 parent e23b911 commit 78a3ea1

File tree

9 files changed

+347
-14
lines changed

9 files changed

+347
-14
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {fireEvent, RenderAPI} from '@testing-library/react-native';
2+
import {ReactTestInstance} from 'react-test-renderer';
3+
import TextDriver from '../text/Text.driver';
4+
import ImageDriver from '../image/Image.driver';
5+
import _ from 'lodash';
6+
7+
8+
const ButtonDriverFactory = async ({wrapperComponent, testID}: {wrapperComponent: RenderAPI, testID: string}) => {
9+
const button: ReactTestInstance | null = await wrapperComponent.queryByTestId(testID);
10+
const label = await TextDriver({wrapperComponent, testID: `${testID}.label`});
11+
const icon = await ImageDriver({wrapperComponent, testID: `${testID}.icon`});
12+
return {
13+
exists: () => !!button,
14+
getRootElement: () => button,
15+
isClickable: () => !_.get(button, 'props.accessibilityState.disabled'),
16+
click: () => {
17+
if (button) {
18+
fireEvent.press(button);
19+
} else {
20+
console.warn(`ButtonDriverFactory: cannot click because testID:${testID} were not found`);
21+
}
22+
},
23+
// label
24+
getLabelRootElement: () => label.getRootElement(),
25+
isLabelExists: () => label.exists(),
26+
getLabelContent: () => label.getTextContent(),
27+
// icon
28+
getIconRootElement: () => icon.getRootElement(),
29+
isIconExists: () => icon.exists()
30+
};
31+
};
32+
33+
export default ButtonDriverFactory;

0 commit comments

Comments
 (0)