Skip to content

Commit

Permalink
feat: Add cancelButtonTestID and confirmButtonTestID props (#582)
Browse files Browse the repository at this point in the history
Add `cancelButtonTestID` and `confirmButtonTestID` props for E2E testing.
  • Loading branch information
Bob Kanellopoulos authored Jul 13, 2021
1 parent 33301ae commit 73a4874
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export default Example;

| Name | Type | Default | Description |
| ----------------------- | --------- | ------------- | --------------------------------------------------------------------------------------------------- |
| cancelButtonTestID | string | | Used to locate cancel button in end-to-end tests. |
| confirmButtonTestID | string | | Used to locate confirm button in end-to-end tests. |
| cancelTextIOS | string | 'Cancel' | The label of the cancel button (iOS) |
| confirmTextIOS | string | 'Confirm' | The label of the confirm button (iOS) |
| customCancelButtonIOS | component | | Overrides the default cancel button component (iOS) |
Expand Down
10 changes: 10 additions & 0 deletions src/DateTimePickerModal.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const TITLE_COLOR = "#8f8f8f";

export class DateTimePickerModal extends React.PureComponent {
static propTypes = {
cancelButtonTestID: PropTypes.string,
confirmButtonTestID: PropTypes.string,
cancelTextIOS: PropTypes.string,
confirmTextIOS: PropTypes.string,
customCancelButtonIOS: PropTypes.elementType,
Expand Down Expand Up @@ -110,6 +112,8 @@ export class DateTimePickerModal extends React.PureComponent {

render() {
const {
cancelButtonTestID,
confirmButtonTestID,
cancelTextIOS,
confirmTextIOS,
customCancelButtonIOS,
Expand Down Expand Up @@ -188,12 +192,14 @@ export class DateTimePickerModal extends React.PureComponent {
/>
</View>
<ConfirmButtonComponent
confirmButtonTestID={confirmButtonTestID}
isDarkModeEnabled={_isDarkModeEnabled}
onPress={this.handleConfirm}
label={confirmTextIOS}
/>
</View>
<CancelButtonComponent
cancelButtonTestID={cancelButtonTestID}
isDarkModeEnabled={_isDarkModeEnabled}
onPress={this.handleCancel}
label={cancelTextIOS}
Expand Down Expand Up @@ -252,6 +258,7 @@ export const headerStyles = StyleSheet.create({

export const ConfirmButton = ({
isDarkModeEnabled,
confirmButtonTestID,
onPress,
label,
style = confirmButtonStyles,
Expand All @@ -265,6 +272,7 @@ export const ConfirmButton = ({
: HIGHLIGHT_COLOR_LIGHT;
return (
<TouchableHighlight
testID={confirmButtonTestID}
style={[themedButtonStyle, style.button]}
underlayColor={underlayColor}
onPress={onPress}
Expand Down Expand Up @@ -300,6 +308,7 @@ export const confirmButtonStyles = StyleSheet.create({
});

export const CancelButton = ({
cancelButtonTestID,
isDarkModeEnabled,
onPress,
label,
Expand All @@ -313,6 +322,7 @@ export const CancelButton = ({
: HIGHLIGHT_COLOR_LIGHT;
return (
<TouchableHighlight
testID={cancelButtonTestID}
style={[style.button, themedButtonStyle]}
underlayColor={underlayColor}
onPress={onPress}
Expand Down

0 comments on commit 73a4874

Please sign in to comment.