Skip to content

Commit

Permalink
Merge pull request #65 from wix/replace_text
Browse files Browse the repository at this point in the history
Added replaceText action
  • Loading branch information
LeoNatan authored Dec 20, 2016
2 parents 59df665 + c91938d commit 876fcea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions detox/src/ios/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ class TypeTextAction extends Action {
}
}


class ReplaceTextAction extends Action {
constructor(value) {
super();
if (typeof value !== 'string') throw new Error(`ReplaceTextAction ctor argument must be a string, got ${typeof value}`);
this._call = invoke.call(invoke.IOS.Class('GREYActions'), 'actionForReplaceText:', value);
}
}

class ClearTextAction extends Action {
constructor() {
super();
Expand Down Expand Up @@ -355,6 +364,9 @@ class Element {
typeText(value) {
return new ActionInteraction(this, new TypeTextAction(value)).execute();
}
replaceText(value) {
return new ActionInteraction(this, new ReplaceTextAction(value)).execute();
}
clearText() {
return new ActionInteraction(this, new ClearTextAction()).execute();
}
Expand Down
6 changes: 6 additions & 0 deletions detox/test/e2e/c-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ describe('Actions', function () {
expect(element(by.label('Clear Working!!!'))).toBeVisible();
});

it('should replace text in an element', function () {
element(by.id('UniqueId006')).tap();
element(by.id('UniqueId006')).replaceText('replaced_text');
expect(element(by.label('Replace Working!!!'))).toBeVisible();
});

// directions: 'up'/'down'/'left'/'right'
it('should scroll for a small amount in direction', function () {
expect(element(by.label('Text1'))).toBeVisible();
Expand Down
17 changes: 17 additions & 0 deletions detox/test/src/Screens/ActionsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export default class ActionsScreen extends Component {
testID='UniqueId005'
/>

<TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1, marginBottom: 20, marginHorizontal: 20, padding: 5}}
onChangeText={this.onReplaceText.bind(this)}
value={this.state.replaceText}
testID='UniqueId006'
/>

<View style={{height: 100, borderColor: '#c0c0c0', borderWidth: 1, backgroundColor: '#f8f8ff', marginBottom: 20}}>
<ScrollView testID='ScrollView161'>
<Text style={{height: 30, backgroundColor: '#e8e8f8', padding: 5, margin: 10}}>Text1</Text>
Expand Down Expand Up @@ -106,6 +112,17 @@ export default class ActionsScreen extends Component {
}
}

onReplaceText(text) {
this.setState({
replaceText: text
});
if (text == 'replaced_text') {
this.setState({
greeting: 'Replace Working'
});
}
}

onChangeClearText(text) {
this.setState({
clearText: text
Expand Down

0 comments on commit 876fcea

Please sign in to comment.