Skip to content

Commit

Permalink
Merge pull request #40 from wix/class-matcher
Browse files Browse the repository at this point in the history
added match by type
  • Loading branch information
Tal Kol authored Oct 10, 2016
2 parents 8613bbc + a67e17c commit f8aaeee
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions detox/ios/Detox/GREYMatchers+Detox.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@

+ (id<GREYMatcher>)detoxMatcherForNot:(id<GREYMatcher>)matcher;

+ (id<GREYMatcher>)detoxMatcherForClass:(NSString *)aClassName;

@end
6 changes: 6 additions & 0 deletions detox/ios/Detox/GREYMatchers+Detox.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ @implementation GREYMatchers (Detox)
return grey_not(matcher);
}

+ (id<GREYMatcher>)detoxMatcherForClass:(NSString *)aClassName
{
Class klass = NSClassFromString(aClassName);
return grey_kindOfClass(klass);
}

@end
12 changes: 11 additions & 1 deletion detox/src/ios/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ class IdMatcher extends Matcher {
}
}

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


class VisibleMatcher extends Matcher {
constructor() {
super();
Expand Down Expand Up @@ -358,7 +367,8 @@ function element(matcher) {

const by = {
label: (value) => new LabelMatcher(value),
id: (value) => new IdMatcher(value)
id: (value) => new IdMatcher(value),
type: (value) => new TypeMatcher(value)
};

const exportGlobals = function () {
Expand Down
6 changes: 6 additions & 0 deletions detox/test/e2e/b-matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ describe('Matchers', function () {
expect(element(by.label('ID Working!!!'))).toBeVisible();
});

it('should match elements by type', function () {
expect(element(by.type('RCTImageView'))).toBeVisible();
element(by.type('RCTImageView')).tap();
expect(element(by.type('RCTImageView'))).toBeNotVisible();
});

});
4 changes: 2 additions & 2 deletions detox/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"dependencies": {
"lodash": "^4.14.1",
"react": "15.1.0",
"react-native": "^0.27.2"
"react": "15.2.1",
"react-native": "0.31.0"
},
"devDependencies": {
"detox": "file:..",
Expand Down
12 changes: 12 additions & 0 deletions detox/test/src/Screens/MatchersScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import {
Text,
View,
Image,
TouchableOpacity
} from 'react-native';

Expand All @@ -27,6 +28,11 @@ export default class MatchersScreen extends Component {
<Text testID='UniqueId345' style={{color: 'blue', marginBottom: 20}}>ID</Text>
</TouchableOpacity>

{!this.state.hideStar ?
<TouchableOpacity onPress={this.onStarPress.bind(this)}>
<Image source={require('../assets/star.png')}/>
</TouchableOpacity> : null}

</View>
);
}
Expand All @@ -47,4 +53,10 @@ export default class MatchersScreen extends Component {
});
}

onStarPress() {
this.setState({
hideStar: true
});
}

}
Binary file added detox/test/src/assets/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8aaeee

Please sign in to comment.