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

expose EarlGrey's matcherForInteractable #668

Closed
Closed
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
4 changes: 3 additions & 1 deletion detox/src/ios/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ExistsMatcher = matchers.ExistsMatcher;
const NotExistsMatcher = matchers.NotExistsMatcher;
const TextMatcher = matchers.TextMatcher;
const ValueMatcher = matchers.ValueMatcher;
const InteractableMatcher = matchers.InteractableMatcher;
const GreyActions = require('./earlgreyapi/GREYActions');

let invocationManager;
Expand Down Expand Up @@ -381,7 +382,8 @@ const by = {
type: (value) => new TypeMatcher(value),
traits: (value) => new TraitsMatcher(value),
value: (value) => new ValueMatcher(value),
text: (value) => new TextMatcher(value)
text: (value) => new TextMatcher(value),
interactable: () => new InteractableMatcher()
};

const exportGlobals = () => {
Expand Down
4 changes: 4 additions & 0 deletions detox/src/ios/expect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ describe('expect', async () => {
await e.expect(e.element(e.by.traits(['startsMedia', 'adjustable', 'allowsDirectInteraction', 'pageTurn']))).toBeNotVisible();
});

it(`element by interactable`, async () => {
await e.expect(e.element(e.by.interactable())).toExist();
});

it(`matcher helpers`, async () => {
await e.expect(e.element(e.by.id('test').withAncestor(e.by.id('ancestor')))).toBeVisible();
await e.expect(e.element(e.by.id('test').withDescendant(e.by.id('descendant')))).toBeVisible();
Expand Down
10 changes: 9 additions & 1 deletion detox/src/ios/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class ValueMatcher extends Matcher {
}
}

class InteractableMatcher extends Matcher {
constructor() {
super();
this._call = invoke.callDirectly(GreyMatchers.matcherForInteractable());
}
}

module.exports = {
Matcher,
LabelMatcher,
Expand All @@ -116,5 +123,6 @@ module.exports = {
ExistsMatcher,
NotExistsMatcher,
TextMatcher,
ValueMatcher
ValueMatcher,
InteractableMatcher
};
5 changes: 5 additions & 0 deletions detox/test/e2e/b-matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ describe('Matchers', () => {
await expect(element(by.text('Product')).atIndex(2)).toHaveId('ProductId002');
});

it(':ios: should match elements by (interactable)', async () => {
await element(by.id('duplicate-testID').and(by.interactable())).tap();
await expect(element(by.text('Interactable Working!!!'))).toBeVisible();
});

});
10 changes: 9 additions & 1 deletion detox/test/src/Screens/MatchersScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,16 @@ export default class MatchersScreen extends Component {
</TouchableOpacity>
<TouchableOpacity onPress={this.onButtonPress.bind(this, 'Third button pressed')}>
<Text style={{color: 'brown', marginBottom: 20}}>Index</Text>
</TouchableOpacity>
</TouchableOpacity>

<View style={{margin: 30, position: 'relative'}}>
<TouchableOpacity testID='duplicate-testID' onPress={this.onButtonPress.bind(this, 'Interactable Not Working')} style={{padding: 20}}>
<Text>overlapped</Text>
</TouchableOpacity>

<TouchableOpacity testID='duplicate-testID' onPress={this.onButtonPress.bind(this, 'Interactable Working')} style={{padding: 40, backgroundColor: 'gray', position: 'absolute', left: 0, right: 0}}>
</TouchableOpacity>
</View>
</View>
);
}
Expand Down