Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added match by type #40

Merged
merged 2 commits into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.