Skip to content

Commit

Permalink
Move GREYConfiguration to generated code (wix#693)
Browse files Browse the repository at this point in the history
* move GREYConfiguration to generated code

* refactor GREYConfiguration callees to use generated APIs

* rename GREYConfigurationApi to GREYConfiguration
  • Loading branch information
DanielMSchmidt authored and rotemmiz committed May 8, 2018
1 parent 6cf3963 commit 2f6dca7
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 42 deletions.
28 changes: 21 additions & 7 deletions detox/src/devices/IosDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const fs = require('fs');
const DeviceDriverBase = require('./DeviceDriverBase');
const InvocationManager = require('../invoke').InvocationManager;
const invoke = require('../invoke');
const GREYConfiguration = require('./../ios/earlgreyapi/GREYConfiguration');
const GREYConfigurationApi = require('./../ios/earlgreyapi/GREYConfiguration');
const GREYConfigurationDetox = require('./../ios/earlgreyapi/GREYConfigurationDetox');

class IosDriver extends DeviceDriverBase {

constructor(client) {
super(client);

Expand All @@ -25,15 +25,29 @@ class IosDriver extends DeviceDriverBase {
}

async setURLBlacklist(urlList) {
await this.client.execute(GREYConfiguration.setURLBlacklist(urlList));
await this.client.execute(
GREYConfigurationApi.setValueForConfigKey(
GREYConfigurationApi.sharedInstance(),
urlList,
"GREYConfigKeyURLBlacklistRegex"
)
);
}

async enableSynchronization() {
await this.client.execute(GREYConfiguration.enableSynchronization());
await this.client.execute(
GREYConfigurationDetox.enableSynchronization(
GREYConfigurationApi.sharedInstance()
)
);
}

async disableSynchronization() {
await this.client.execute(GREYConfiguration.disableSynchronization());
await this.client.execute(
GREYConfigurationDetox.disableSynchronization(
GREYConfigurationApi.sharedInstance()
)
);
}

async shake(deviceId) {
Expand All @@ -44,10 +58,10 @@ class IosDriver extends DeviceDriverBase {
// keys are possible orientations
const orientationMapping = {
landscape: 3, // top at left side landscape
portrait: 1 // non-reversed portrait
portrait: 1 // non-reversed portrait
};
if (!Object.keys(orientationMapping).includes(orientation)) {
throw new Error(`setOrientation failed: provided orientation ${orientation} is not part of supported orientations: ${Object.keys(orientationMapping)}`)
throw new Error(`setOrientation failed: provided orientation ${orientation} is not part of supported orientations: ${Object.keys(orientationMapping)}`);
}

const call = invoke.call(invoke.EarlGrey.instance,
Expand Down
200 changes: 170 additions & 30 deletions detox/src/ios/earlgreyapi/GREYConfiguration.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,179 @@
/**
const invoke = require('../../invoke');
This code is generated.
For more information see generation/README.md.
*/

/**
* An 'invoke' wrapper for https://github.com/google/EarlGrey/blob/master/EarlGrey/Common/GREYConfiguration.h
*/

/**
*
* @param blacklist - array of regular expressions, every matched URL will be ignored. example: [".*www\\.google\\.com", ".*www\\.youtube\\.com"]
* @returns {*}
*/
function setURLBlacklist(blacklist) {
return setValueForConfigKey(blacklist, 'GREYConfigKeyURLBlacklistRegex');
}

function enableSynchronization() {
//return setValueForConfigKey(invoke.IOS.Boolean(true), 'kGREYConfigKeySynchronizationEnabled');
return invoke.call(GREYConfigurationInstance(), 'enableSynchronization');
}
class GREYConfiguration {
/*@return The singleton GREYConfiguration instance.
*/static sharedInstance() {
return {
target: {
type: "Class",
value: "GREYConfiguration"
},
method: "sharedInstance",
args: []
};
}

function disableSynchronization() {
//return setValueForConfigKey(invoke.IOS.Boolean(false), 'kGREYConfigKeySynchronizationEnabled');
return invoke.call(GREYConfigurationInstance(), 'disableSynchronization');
}
/*If a user-configured value is associated with the given @c configKey, it is returned,
otherwise the default value is returned. If a default value is not found, or an
NSInvalidArgumentException is raised.
function setValueForConfigKey(value, configKey) {
return invoke.call(GREYConfigurationInstance(), 'setValue:forConfigKey:', value, configKey);
}
@param configKey The key whose value is being queried. Must be a valid @c NSString.
@throws NSInvalidArgumentException If no value could be found associated with @c configKey.
@return The value for the configuration stored associate with @c configKey.
*/static valueForConfigKey(element, configKey) {
if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")"))));
return {
target: {
type: "Invocation",
value: element
},
method: "valueForConfigKey:",
args: [{
type: "NSString",
value: configKey
}]
};
}

/*If a user-configured value is associated with the given @c configKey, it is returned, otherwise
the default value is returned. If a default value is not found, NSInvalidArgumentException is
raised.
@param configKey The key whose value is being queried. Must be a valid @c NSString.
@throws NSInvalidArgumentException If no value could be found for the given @c configKey.
@return The @c BOOL value for the configuration associated with @c configKey.
*/static boolValueForConfigKey(element, configKey) {
if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")"))));
return {
target: {
type: "Invocation",
value: element
},
method: "boolValueForConfigKey:",
args: [{
type: "NSString",
value: configKey
}]
};
}

/*If a user-configured value is associated with the given @c configKey, it is returned, otherwise
the default value is returned. If a default value is not found, NSInvalidArgumentException is
raised.
@param configKey The key whose value is being queried. Must be a valid @c NSString.
@throws NSInvalidArgumentException If no value could be found for the given @c configKey.
@return The integer value for the configuration associated with @c configKey.
*/static integerValueForConfigKey(element, configKey) {
if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")"))));
return {
target: {
type: "Invocation",
value: element
},
method: "integerValueForConfigKey:",
args: [{
type: "NSString",
value: configKey
}]
};
}

/*If a user-configured value is associated with the given @c configKey, it is returned, otherwise
the default value is returned. If a default value is not found, NSInvalidArgumentException is
raised.
@param configKey The key whose value is being queried. Must be a valid @c NSString.
@throws NSInvalidArgumentException If no value could be found for the given @c configKey.
@return The @c double value for the configuration associated with @c configKey.
*/static doubleValueForConfigKey(element, configKey) {
if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")"))));
return {
target: {
type: "Invocation",
value: element
},
method: "doubleValueForConfigKey:",
args: [{
type: "NSString",
value: configKey
}]
};
}

/*Resets all configurations to default values, removing all the configured values.
@remark Any default values added by calling GREYConfiguration:setDefaultValue:forConfigKey:
are not reset.
*/static reset(element) {
return {
target: {
type: "Invocation",
value: element
},
method: "reset",
args: []
};
}

/*Given a value and a key that identifies a configuration, set the value of the configuration.
Overwrites any previous value for the configuration.
@remark To restore original values, call GREYConfiguration::reset.
@param value The configuration value to be set. Scalars should be wrapped in @c NSValue.
@param configKey Key identifying an existing or new configuration. Must be a valid @c NSString.
*/static setValueForConfigKey(element, value, configKey) {
if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")"))));
return {
target: {
type: "Invocation",
value: element
},
method: "setValue:forConfigKey:",
args: [value, {
type: "NSString",
value: configKey
}]
};
}

/*Associates configuration identified by @c configKey with the provided @c value.
@remark Default values persist even after resetting the configuration
(using GREYConfiguration::reset)
@param value The configuration value to be set. Scalars should be wrapped in @c NSValue.
@param configKey Key identifying an existing or new configuration. Must be a valid @c NSString.
*/static setDefaultValueForConfigKey(element, value, configKey) {
if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")"))));
return {
target: {
type: "Invocation",
value: element
},
method: "setDefaultValue:forConfigKey:",
args: [value, {
type: "NSString",
value: configKey
}]
};
}

function GREYConfigurationInstance() {
return invoke.call(invoke.IOS.Class('GREYConfiguration'), 'sharedInstance');
}

module.exports = {
setURLBlacklist,
enableSynchronization,
disableSynchronization
};
module.exports = GREYConfiguration;
34 changes: 34 additions & 0 deletions detox/src/ios/earlgreyapi/GREYConfigurationDetox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
This code is generated.
For more information see generation/README.md.
*/



class GREYConfiguration {
static enableSynchronization(element) {
return {
target: {
type: "Invocation",
value: element
},
method: "enableSynchronization",
args: []
};
}

static disableSynchronization(element) {
return {
target: {
type: "Invocation",
value: element
},
method: "disableSynchronization",
args: []
};
}

}

module.exports = GREYConfiguration;
55 changes: 55 additions & 0 deletions detox/src/ios/earlgreyapi/GREYMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,61 @@ is required, please implement it similar to @c grey_closeTo.
};
}

/*A Matcher that checks if a provided object is equal to the specified @c value. The equality is
determined by calling the @c isEqual: method of the object being examined. In case the @c
value is @c nil, then the object itself is checked to be @c nil.
@param value The value to be checked for equality. Please ensure that scalar types are
passed in as boxed (object) values.
@return A matcher that checks if an object is equal to the provided one.
*/static matcherForEqualTo(value) {
return {
target: {
type: "Class",
value: "GREYMatchers"
},
method: "matcherForEqualTo:",
args: [value]
};
}

/*A Matcher that checks if a provided object is less than a specified @c value. The comparison
is made by calling the @c compare: method of the object being examined.
@param value The value to be compared, which should return @c NSOrderedDescending. Please
ensure that scalar values are passed in as boxed (object) values.
@return A matcher that checks an object is lesser than another provided @c value.
*/static matcherForLessThan(value) {
return {
target: {
type: "Class",
value: "GREYMatchers"
},
method: "matcherForLessThan:",
args: [value]
};
}

/*A Matcher that checks if a provided object is greater than a specified @c value. The comparison
is made by calling the @c compare: method of the object being examined.
@param value The value to be compared, which should return @c NSOrderedAscending. Please
ensure that scalar values are passed in as boxed (object) values.
@return A matcher that checks an object is greater than another provided @c value.
*/static matcherForGreaterThan(value) {
return {
target: {
type: "Class",
value: "GREYMatchers"
},
method: "matcherForGreaterThan:",
args: [value]
};
}

/*Matcher that matches a UIScrollView scrolled to content @c edge.
@param edge The content edge UIScrollView should be scrolled to.
Expand Down
9 changes: 6 additions & 3 deletions generation/adapters/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const {
isGreyAction,
isGreyMatcher,
isGreyElementInteraction,
isArray
isArray,
isDefined
} = require("../core/type-checks");
const { callGlobal } = require("../helpers");

Expand All @@ -29,7 +30,8 @@ const typeCheckInterfaces = {
"id<GREYAction>": isGreyAction,
"id<GREYMatcher>": isGreyMatcher,
"GREYElementInteraction*": isGreyElementInteraction,
UIAccessibilityTraits: isArray
UIAccessibilityTraits: isArray,
id: isDefined,
};

const contentSanitizersForType = {
Expand Down Expand Up @@ -72,7 +74,8 @@ module.exports = generator({
"id<GREYAction>",
"id<GREYMatcher>",
"CFTimeInterval",
"UIAccessibilityTraits"
"UIAccessibilityTraits",
"id"
],
renameTypesMap: {
NSUInteger: "NSInteger",
Expand Down
Loading

0 comments on commit 2f6dca7

Please sign in to comment.