-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add support for generating android matchers #425
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
This code is generated. | ||
For more information see generation/README.md. | ||
*/ | ||
|
||
|
||
// Globally declared helpers | ||
|
||
function sanitize_greyDirection(action) { | ||
switch (action) { | ||
case "left": | ||
return 1; | ||
case "right": | ||
return 2; | ||
case "up": | ||
return 3; | ||
case "down": | ||
return 4; | ||
|
||
default: | ||
throw new Error(`GREYAction.GREYDirection must be a 'left'/'right'/'up'/'down', got ${action}`); | ||
} | ||
} | ||
|
||
function sanitize_greyContentEdge(action) { | ||
switch (action) { | ||
case "left": | ||
return 0; | ||
case "right": | ||
return 1; | ||
case "top": | ||
return 2; | ||
case "bottom": | ||
return 3; | ||
|
||
default: | ||
throw new Error(`GREYAction.GREYContentEdge must be a 'left'/'right'/'top'/'bottom', got ${action}`); | ||
} | ||
} | ||
|
||
function sanitize_uiAccessibilityTraits(value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same applies here |
||
let traits = 0; | ||
for (let i = 0; i < value.length; i++) { | ||
switch (value[i]) { | ||
case 'button': traits |= 1; break; | ||
case 'link': traits |= 2; break; | ||
case 'header': traits |= 4; break; | ||
case 'search': traits |= 8; break; | ||
case 'image': traits |= 16; break; | ||
case 'selected': traits |= 32; break; | ||
case 'plays': traits |= 64; break; | ||
case 'key': traits |= 128; break; | ||
case 'text': traits |= 256; break; | ||
case 'summary': traits |= 512; break; | ||
case 'disabled': traits |= 1024; break; | ||
case 'frequentUpdates': traits |= 2048; break; | ||
case 'startsMedia': traits |= 4096; break; | ||
case 'adjustable': traits |= 8192; break; | ||
case 'allowsDirectInteraction': traits |= 16384; break; | ||
case 'pageTurn': traits |= 32768; break; | ||
default: throw new Error(`Unknown trait '${value[i]}', see list in https://facebook.github.io/react-native/docs/accessibility.html#accessibilitytraits-ios`); | ||
} | ||
} | ||
|
||
return traits; | ||
} | ||
|
||
|
||
|
||
class DetoxAction { | ||
static multiClick(times) { | ||
if (typeof times !== "number") throw new Error("times should be a number, but got " + (times + (" (" + (typeof times + ")")))); | ||
return { | ||
target: { | ||
type: "Class", | ||
value: "com.wix.detox.espresso.DetoxAction" | ||
}, | ||
method: "multiClick", | ||
args: [{ | ||
type: "Integer", | ||
value: times | ||
}] | ||
}; | ||
} | ||
|
||
static tapAtLocation(x, y) { | ||
if (typeof x !== "number") throw new Error("x should be a number, but got " + (x + (" (" + (typeof x + ")")))); | ||
if (typeof y !== "number") throw new Error("y should be a number, but got " + (y + (" (" + (typeof y + ")")))); | ||
return { | ||
target: { | ||
type: "Class", | ||
value: "com.wix.detox.espresso.DetoxAction" | ||
}, | ||
method: "tapAtLocation", | ||
args: [{ | ||
type: "Integer", | ||
value: x | ||
}, { | ||
type: "Integer", | ||
value: y | ||
}] | ||
}; | ||
} | ||
|
||
static scrollToEdge(edge) { | ||
if (typeof edge !== "number") throw new Error("edge should be a number, but got " + (edge + (" (" + (typeof edge + ")")))); | ||
return { | ||
target: { | ||
type: "Class", | ||
value: "com.wix.detox.espresso.DetoxAction" | ||
}, | ||
method: "scrollToEdge", | ||
args: [{ | ||
type: "Integer", | ||
value: edge | ||
}] | ||
}; | ||
} | ||
|
||
static scrollInDirection(direction, amountInDP) { | ||
if (typeof direction !== "number") throw new Error("direction should be a number, but got " + (direction + (" (" + (typeof direction + ")")))); | ||
if (typeof amountInDP !== "number") throw new Error("amountInDP should be a number, but got " + (amountInDP + (" (" + (typeof amountInDP + ")")))); | ||
return { | ||
target: { | ||
type: "Class", | ||
value: "com.wix.detox.espresso.DetoxAction" | ||
}, | ||
method: "scrollInDirection", | ||
args: [{ | ||
type: "Integer", | ||
value: direction | ||
}, { | ||
type: "double", | ||
value: amountInDP | ||
}] | ||
}; | ||
} | ||
|
||
} | ||
|
||
module.exports = DetoxAction; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
const invoke = require('../invoke'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you want to add the other actions as well ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran the e2e suite with the old implementation, will re-run it the next days with the newer one. As I said, I would like to add the actions step by step to have smaller, easier to merge PRs. |
||
const matchers = require('./matcher'); | ||
const DetoxActionApi = require('./espressoapi/DetoxAction'); | ||
const Matcher = matchers.Matcher; | ||
const LabelMatcher = matchers.LabelMatcher; | ||
const IdMatcher = matchers.IdMatcher; | ||
|
@@ -51,7 +52,7 @@ class LongPressAction extends Action { | |
class MultiClickAction extends Action { | ||
constructor(times) { | ||
super(); | ||
this._call = invoke.call(invoke.Android.Class(DetoxAction), 'multiClick', invoke.Android.Integer(times)); | ||
this._call = invoke.callDirectly(DetoxActionApi.multiClick(times)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Android generation methods should generate type checks 1`] = `"times should be a number, but got FOO (string)"`; | ||
|
||
exports[`Android generation methods should return adapter calls 1`] = ` | ||
Object { | ||
"args": Array [ | ||
Object { | ||
"type": "Integer", | ||
"value": 3, | ||
}, | ||
], | ||
"method": "multiClick", | ||
"target": Object { | ||
"type": "Class", | ||
"value": "com.wix.detox.espresso.DetoxAction", | ||
}, | ||
} | ||
`; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated, probably needs to be removed in the generation code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a seperate PR. The generation is currently "dump" and nothing keeps track if these functions are needed or not. It might be a little more complex and unrelated to this set of changes to remove these in the generation. But it's one of my next ups on the list