Skip to content

Commit

Permalink
Functionality for testing picker ios (#605)
Browse files Browse the repository at this point in the history
Implement functionality for changing the column values of pickers on IOS
  • Loading branch information
DmitryPonomarenko authored and yershalom committed Apr 4, 2018
1 parent ae15bbf commit 7b4a2f0
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 6 deletions.
3 changes: 2 additions & 1 deletion detox/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"eslint.enable": false
"eslint.enable": false,
"git.ignoreLimitWarning": true
}
10 changes: 10 additions & 0 deletions detox/src/ios/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ class SwipeAction extends Action {
}
}

class ScrollColumnToValue extends Action {
constructor(column,value) {
super();
this._call = invoke.callDirectly(GreyActions.actionForSetPickerColumnToValue(column,value))
}
}

class Interaction {
async execute() {
//if (!this._call) throw new Error(`Interaction.execute cannot find a valid _call, got ${typeof this._call}`);
Expand Down Expand Up @@ -284,6 +291,9 @@ class Element {
this._selectElementWithMatcher(this._originalMatcher._avoidProblematicReactNativeElements());
return await new ActionInteraction(this, new SwipeAction(direction, speed, percentage)).execute();
}
async setColumnToValue(column,value) {
return await new ActionInteraction(this, new ScrollColumnToValue(column, value)).execute();
}
}

class Expect {}
Expand Down
3 changes: 3 additions & 0 deletions detox/src/ios/expect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('expect', async () => {

it(`element by type`, async () => {
await e.expect(e.element(e.by.type('test'))).toBeVisible();
await e.element(e.by.type('UIPickerView')).setColumnToValue(1,"6");
});

it(`element by traits`, async () => {
Expand Down Expand Up @@ -79,6 +80,8 @@ describe('expect', async () => {
await e.waitFor(e.element(e.by.id('id'))).toHaveValue('value');
await e.waitFor(e.element(e.by.id('id'))).toNotHaveValue('value');



await e.waitFor(e.element(e.by.id('id'))).toBeVisible().whileElement(e.by.id('id2')).scroll(50, 'down');
await e.waitFor(e.element(e.by.id('id'))).toBeVisible().whileElement(e.by.id('id2')).scroll(50);
});
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions detox/test/e2e/s-datePicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
describe('DatePicker', () => {
beforeEach(async () => {
await device.reloadReactNative();
});

beforeEach(async () => {
await element(by.text('DatePicker')).tap();
});

it('datePicker should trigger change handler correctly', async () => {
await element(by.type('UIPickerView')).setColumnToValue(1,"6");
await element(by.type('UIPickerView')).setColumnToValue(2,"34");
await expect(element(by.id("timeLabel"))).toHaveText('choosenTime is 6:34');
});

});

4 changes: 2 additions & 2 deletions detox/test/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = org.reactjs.native.example;
PRODUCT_NAME = example;
};
name = Debug;
Expand All @@ -1162,7 +1162,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = org.reactjs.native.example;
PRODUCT_NAME = example;
};
name = Release;
Expand Down
59 changes: 59 additions & 0 deletions detox/test/src/Screens/DatePickerScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { Component } from 'react';
import {
Text,
View,
StyleSheet,
DatePickerIOS
} from 'react-native';

export default class DatePickerScreen extends Component {

constructor(props) {
super(props);
this.state = {
chosenDate: new Date()
}
this._setDate = this._setDate.bind(this);
}

_setDate(newDate) {
this.setState({
chosenDate :newDate
})
}

getTime() {
minutes = this.state.chosenDate.getMinutes()
hour = this.state.chosenDate.getHours()
if( hour > 12 ) {
hour = hour - 12;
}
return `${hour}:${minutes}`
}

render() {
return (
<View style={{flex: 1, paddingTop: 20, justifyContent: 'center', alignItems: 'center'}}>
<Text style = {styles.dateText} testID='timeLabel'>
{"choosenTime is " + this.getTime()}
</Text>
<DatePickerIOS
style = {styles.datePicker}
date = {this.state.chosenDate}
onDateChange={this._setDate}
/>
</View>
);
}
}

const styles = StyleSheet.create({
datePicker: {
width:'100%',
height:200,
backgroundColor:'green',
},
dateText: {
textAlign: 'center',
}
});
4 changes: 3 additions & 1 deletion detox/test/src/Screens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import NetworkScreen from './NetworkScreen';
import AnimationsScreen from './AnimationsScreen';
import LocationScreen from './LocationScreen';
import ShakeScreen from './ShakeScreen';
import DatePickerScreen from './DatePickerScreen'

export {
SanityScreen,
Expand All @@ -27,5 +28,6 @@ export {
NetworkScreen,
AnimationsScreen,
LocationScreen,
ShakeScreen
ShakeScreen,
DatePickerScreen
};
1 change: 1 addition & 0 deletions detox/test/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class example extends Component {
{this.renderScreenButton('Network', Screens.NetworkScreen)}
{this.renderScreenButton('Animations', Screens.AnimationsScreen)}
{this.renderScreenButton('Location', Screens.LocationScreen)}
{this.renderScreenButton('DatePicker', Screens.DatePickerScreen)}
{this.renderButton('Crash', () => {
throw new Error('Simulated Crash')
})}
Expand Down
11 changes: 11 additions & 0 deletions docs/APIRef.ActionsOnElement.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Actions are functions that emulate user behavior. They are being performed on ma
- [`.scroll()`](#scrollpixels-direction)
- [`.scrollTo()`](#scrolltoedge)
- [`.swipe()`](#swipedirection-speed-percentage)
- [`.setColumnToValue()`](#setcolumntovalue-column-value) **iOS only**


### `tap()`
Expand Down Expand Up @@ -107,3 +108,13 @@ await element(by.id('scrollView')).swipe('down');
await element(by.id('scrollView')).swipe('down', 'fast');
await element(by.id('scrollView')).swipe('down', 'fast', 0.5);
```
### `setColumnToValue(column,value)` iOS only

column - number of datepicker column (starts from 0)
value - string value in setted column (must be correct)

```js
await expect(element(by.type('UIPickerView'))).toBeVisible();
await element(by.type('UIPickerView')).setColumnToValue(1,"6");
await element(by.type('UIPickerView')).setColumnToValue(2,"34");
```
2 changes: 1 addition & 1 deletion generation/core/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module.exports = function({
t.identifier("value"),
addArgumentContentSanitizerCall(arg, json.name)
)
])
])
: addArgumentContentSanitizerCall(arg, json.name)
);

Expand Down
2 changes: 1 addition & 1 deletion generation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"babel-template": "^6.26.0",
"java-method-parser": "^0.4.5"
}
}
}

0 comments on commit 7b4a2f0

Please sign in to comment.