Skip to content

Commit

Permalink
move expect to generated code
Browse files Browse the repository at this point in the history
Closes #726
  • Loading branch information
Daniel Schmidt committed Nov 24, 2018
1 parent 118eb73 commit 1395964
Show file tree
Hide file tree
Showing 16 changed files with 467 additions and 227 deletions.
105 changes: 105 additions & 0 deletions detox/src/android/espressoapi/DetoxAssertion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
This code is generated.
For more information see generation/README.md.
*/


function sanitize_matcher(matcher) {
if (!matcher._call) {
return matcher;
}

const originalMatcher = typeof matcher._call === 'function' ? matcher._call() : matcher._call;
return originalMatcher.type ? originalMatcher.value : originalMatcher;
}
class DetoxAssertion {
static assertMatcher(i, m) {
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAssertion"
},
method: "assertMatcher",
args: [{
type: "Invocation",
value: i
}, {
type: "Invocation",
value: sanitize_matcher(m)
}]
};
}

static assertNotVisible(i) {
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAssertion"
},
method: "assertNotVisible",
args: [{
type: "Invocation",
value: i
}]
};
}

static assertNotExists(i) {
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAssertion"
},
method: "assertNotExists",
args: [{
type: "Invocation",
value: i
}]
};
}

static waitForAssertMatcher(i, m, timeoutSeconds) {
if (typeof timeoutSeconds !== "number") throw new Error("timeoutSeconds should be a number, but got " + (timeoutSeconds + (" (" + (typeof timeoutSeconds + ")"))));
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAssertion"
},
method: "waitForAssertMatcher",
args: [{
type: "Invocation",
value: i
}, {
type: "Invocation",
value: sanitize_matcher(m)
}, {
type: "Double",
value: timeoutSeconds
}]
};
}

static waitForAssertMatcherWithSearchAction(i, m, searchAction, searchMatcher) {
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.DetoxAssertion"
},
method: "waitForAssertMatcherWithSearchAction",
args: [{
type: "Invocation",
value: i
}, {
type: "Invocation",
value: sanitize_matcher(m)
}, searchAction, {
type: "Invocation",
value: sanitize_matcher(searchMatcher)
}]
};
}

}

module.exports = DetoxAssertion;
65 changes: 4 additions & 61 deletions detox/src/android/espressoapi/DetoxMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@


function sanitize_matcher(matcher) {
if (!matcher._call) {
return matcher;
}

const originalMatcher = typeof matcher._call === 'function' ? matcher._call() : matcher._call;
return originalMatcher.type ? originalMatcher.value : originalMatcher;
}
Expand Down Expand Up @@ -47,18 +51,6 @@ class DetoxMatcher {
}

static matcherForAnd(m1, m2) {
if (typeof m1 !== 'object' || typeof m1.constructor !== 'function' || m1.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof m1 === 'object';
const additionalErrorInfo = isObject ? typeof m1.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m1.constructor.name + '"' : 'it is no object';
throw new Error('m1 should be an instance of Matcher, got "' + m1 + '", it appears that ' + additionalErrorInfo);
}

if (typeof m2 !== 'object' || typeof m2.constructor !== 'function' || m2.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof m2 === 'object';
const additionalErrorInfo = isObject ? typeof m2.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m2.constructor.name + '"' : 'it is no object';
throw new Error('m2 should be an instance of Matcher, got "' + m2 + '", it appears that ' + additionalErrorInfo);
}

return {
target: {
type: "Class",
Expand All @@ -76,18 +68,6 @@ class DetoxMatcher {
}

static matcherForOr(m1, m2) {
if (typeof m1 !== 'object' || typeof m1.constructor !== 'function' || m1.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof m1 === 'object';
const additionalErrorInfo = isObject ? typeof m1.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m1.constructor.name + '"' : 'it is no object';
throw new Error('m1 should be an instance of Matcher, got "' + m1 + '", it appears that ' + additionalErrorInfo);
}

if (typeof m2 !== 'object' || typeof m2.constructor !== 'function' || m2.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof m2 === 'object';
const additionalErrorInfo = isObject ? typeof m2.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m2.constructor.name + '"' : 'it is no object';
throw new Error('m2 should be an instance of Matcher, got "' + m2 + '", it appears that ' + additionalErrorInfo);
}

return {
target: {
type: "Class",
Expand All @@ -105,12 +85,6 @@ class DetoxMatcher {
}

static matcherForNot(m) {
if (typeof m !== 'object' || typeof m.constructor !== 'function' || m.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof m === 'object';
const additionalErrorInfo = isObject ? typeof m.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m.constructor.name + '"' : 'it is no object';
throw new Error('m should be an instance of Matcher, got "' + m + '", it appears that ' + additionalErrorInfo);
}

return {
target: {
type: "Class",
Expand All @@ -125,18 +99,6 @@ class DetoxMatcher {
}

static matcherWithAncestor(m, ancestorMatcher) {
if (typeof m !== 'object' || typeof m.constructor !== 'function' || m.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof m === 'object';
const additionalErrorInfo = isObject ? typeof m.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m.constructor.name + '"' : 'it is no object';
throw new Error('m should be an instance of Matcher, got "' + m + '", it appears that ' + additionalErrorInfo);
}

if (typeof ancestorMatcher !== 'object' || typeof ancestorMatcher.constructor !== 'function' || ancestorMatcher.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof ancestorMatcher === 'object';
const additionalErrorInfo = isObject ? typeof ancestorMatcher.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + ancestorMatcher.constructor.name + '"' : 'it is no object';
throw new Error('ancestorMatcher should be an instance of Matcher, got "' + ancestorMatcher + '", it appears that ' + additionalErrorInfo);
}

return {
target: {
type: "Class",
Expand All @@ -154,18 +116,6 @@ class DetoxMatcher {
}

static matcherWithDescendant(m, descendantMatcher) {
if (typeof m !== 'object' || typeof m.constructor !== 'function' || m.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof m === 'object';
const additionalErrorInfo = isObject ? typeof m.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + m.constructor.name + '"' : 'it is no object';
throw new Error('m should be an instance of Matcher, got "' + m + '", it appears that ' + additionalErrorInfo);
}

if (typeof descendantMatcher !== 'object' || typeof descendantMatcher.constructor !== 'function' || descendantMatcher.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof descendantMatcher === 'object';
const additionalErrorInfo = isObject ? typeof descendantMatcher.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + descendantMatcher.constructor.name + '"' : 'it is no object';
throw new Error('descendantMatcher should be an instance of Matcher, got "' + descendantMatcher + '", it appears that ' + additionalErrorInfo);
}

return {
target: {
type: "Class",
Expand Down Expand Up @@ -240,13 +190,6 @@ class DetoxMatcher {

static matcherForAtIndex(index, innerMatcher) {
if (typeof index !== "number") throw new Error("index should be a number, but got " + (index + (" (" + (typeof index + ")"))));

if (typeof innerMatcher !== 'object' || typeof innerMatcher.constructor !== 'function' || innerMatcher.constructor.name.indexOf('Matcher') === -1) {
const isObject = typeof innerMatcher === 'object';
const additionalErrorInfo = isObject ? typeof innerMatcher.constructor === 'object' ? 'the constructor is no object' : 'it has a wrong class name: "' + innerMatcher.constructor.name + '"' : 'it is no object';
throw new Error('innerMatcher should be an instance of Matcher, got "' + innerMatcher + '", it appears that ' + additionalErrorInfo);
}

return {
target: {
type: "Class",
Expand Down
14 changes: 14 additions & 0 deletions detox/src/android/espressoapi/EspressoDetox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@


class EspressoDetox {
static perform(interaction, action) {
return {
target: {
type: "Class",
value: "com.wix.detox.espresso.EspressoDetox"
},
method: "perform",
args: [{
type: "Invocation",
value: interaction
}, action]
};
}

static changeOrientation(orientation) {
if (typeof orientation !== "number") throw new Error("orientation should be a number, but got " + (orientation + (" (" + (typeof orientation + ")"))));
return {
Expand Down
60 changes: 35 additions & 25 deletions detox/src/android/espressoapi/UIDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,31 +151,41 @@ class UiDevice {
}

static pressKeyCode(element, keyCode) {
if (typeof keyCode !== "number") throw new Error("keyCode should be a number, but got " + (keyCode + (" (" + (typeof keyCode + ")"))));
return {
target: element,
method: "pressKeyCode",
args: [{
type: "Integer",
value: keyCode
}]
};
}

static pressKeyCode(element, keyCode, metaState) {
if (typeof keyCode !== "number") throw new Error("keyCode should be a number, but got " + (keyCode + (" (" + (typeof keyCode + ")"))));
if (typeof metaState !== "number") throw new Error("metaState should be a number, but got " + (metaState + (" (" + (typeof metaState + ")"))));
return {
target: element,
method: "pressKeyCode",
args: [{
type: "Integer",
value: keyCode
}, {
type: "Integer",
value: metaState
}]
};
function pressKeyCode1(keyCode) {
if (typeof keyCode !== "number") throw new Error("keyCode should be a number, but got " + (keyCode + (" (" + (typeof keyCode + ")"))));
return {
target: element,
method: "pressKeyCode",
args: [{
type: "Integer",
value: keyCode
}]
};
}

function pressKeyCode2(keyCode, metaState) {
if (typeof keyCode !== "number") throw new Error("keyCode should be a number, but got " + (keyCode + (" (" + (typeof keyCode + ")"))));
if (typeof metaState !== "number") throw new Error("metaState should be a number, but got " + (metaState + (" (" + (typeof metaState + ")"))));
return {
target: element,
method: "pressKeyCode",
args: [{
type: "Integer",
value: keyCode
}, {
type: "Integer",
value: metaState
}]
};
}

if (arguments.length === 1) {
return pressKeyCode1.apply(null, arguments);
}

if (arguments.length === 2) {
return pressKeyCode2.apply(null, arguments);
}
}

static pressRecentApps(element) {
Expand Down
Loading

0 comments on commit 1395964

Please sign in to comment.