-
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
Move iOS Device rotation to generated code #727
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
|
||
This code is generated. | ||
For more information see generation/README.md. | ||
*/ | ||
|
||
|
||
function sanitize_uiDeviceOrientation(value) { | ||
const orientationMapping = { | ||
landscape: 3, // top at left side landscape | ||
portrait: 1 // non-reversed portrait | ||
}; | ||
|
||
return orientationMapping[value]; | ||
} | ||
class EarlGreyImpl { | ||
/*Provides the file name and line number of the code that is calling into EarlGrey. | ||
In case of a failure, the information is used to tell XCTest the exact line which caused | ||
the failure so it can be highlighted in the IDE. | ||
|
||
@param fileName The name of the file where the failing code exists. | ||
@param lineNumber The line number of the failing code. | ||
|
||
@return An EarlGreyImpl instance, with details of the code invoking EarlGrey. | ||
*/static invokedFromFileLineNumber(fileName, lineNumber) { | ||
if (typeof fileName !== "string") throw new Error("fileName should be a string, but got " + (fileName + (" (" + (typeof fileName + ")")))); | ||
if (typeof lineNumber !== "number") throw new Error("lineNumber should be a number, but got " + (lineNumber + (" (" + (typeof lineNumber + ")")))); | ||
return { | ||
target: { | ||
type: "Class", | ||
value: "EarlGreyImpl" | ||
}, | ||
method: "invokedFromFile:lineNumber:", | ||
args: [{ | ||
type: "NSString", | ||
value: fileName | ||
}, { | ||
type: "NSInteger", | ||
value: lineNumber | ||
}] | ||
}; | ||
} | ||
|
||
/*Rotate the device to a given @c deviceOrientation. All device orientations except for | ||
@c UIDeviceOrientationUnknown are supported. If a non-nil @c errorOrNil is provided, it will | ||
be populated with the failure reason if the orientation change fails, otherwise a test failure | ||
will be registered. | ||
|
||
@param deviceOrientation The desired orientation of the device. | ||
@param[out] errorOrNil Error that will be populated on failure. If @c nil, a test | ||
failure will be reported if the rotation attempt fails. | ||
|
||
@return @c YES if the rotation was successful, @c NO otherwise. | ||
*/static rotateDeviceToOrientationErrorOrNil(element, deviceOrientation) { | ||
if (!["landscape", "portrait"].some(option => option === deviceOrientation)) throw new Error("deviceOrientation should be one of [landscape, portrait], but got " + deviceOrientation); | ||
return { | ||
target: element, | ||
method: "rotateDeviceToOrientation:errorOrNil:", | ||
args: [{ | ||
type: "NSInteger", | ||
value: sanitize_uiDeviceOrientation(deviceOrientation) | ||
}] | ||
}; | ||
} | ||
|
||
/*Dismisses the keyboard by resigning the first responder, if any. Will populate the provided | ||
error if the first responder is not present or if the keyboard is not visible. | ||
|
||
@param[out] errorOrNil Error that will be populated on failure. If @c nil, a test | ||
failure will be reported if the dismissing fails. | ||
|
||
@return @c YES if the dismissing of the keyboard was successful, @c NO otherwise. | ||
*/static dismissKeyboardWithError(element) { | ||
return { | ||
target: element, | ||
method: "dismissKeyboardWithError:", | ||
args: [] | ||
}; | ||
} | ||
|
||
} | ||
|
||
module.exports = EarlGreyImpl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any reason why not expose all options?
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.
It's just a refactoring, I would rather improve the situation a different PR :)
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.
We could create an issue, it's probably a very good first issue 🤔
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.
I don’t understand. We have no usage of Earl Grey rotation so far. If this PR introduces it, why do we need additional issues or PRs?
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.
We have and this is the actual mapping we are currently using: https://github.com/wix/detox/blob/master/detox/src/devices/IosDriver.js#L59-L62
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.
It was my first bigger PR in detox 😻
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.
Eh I confused rotate with shake.
In either case, what blocks the full enum being exposed here?
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.
Not much, I just would like to first transfer it and afterwards add the new cases. That way I surely don't touch tests and refactorings in one PR