From 9fe9d2e5341a0ace14a2190a71f122eb9e7f7adc Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Mon, 14 Aug 2017 23:53:39 +0200 Subject: [PATCH] fix GREYDirection type mismatch This closes #228 --- detox/src/ios/earlgreyapi/GREYActions.js | 20 +++++++++---------- .../__tests__/__snapshots__/earl-grey.js.snap | 2 +- generation/__tests__/earl-grey.js | 2 +- generation/earl-grey/index.js | 19 +++++++++++++++--- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/detox/src/ios/earlgreyapi/GREYActions.js b/detox/src/ios/earlgreyapi/GREYActions.js index 4631a69344..218287e87e 100644 --- a/detox/src/ios/earlgreyapi/GREYActions.js +++ b/detox/src/ios/earlgreyapi/GREYActions.js @@ -144,7 +144,7 @@ simulate a long press. }, method: "actionForScrollInDirection:amount:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }, { type: "CGFloat", @@ -181,7 +181,7 @@ starting from the given start points. }, method: "actionForScrollInDirection:amount:xOriginStartPercentage:yOriginStartPercentage:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }, { type: "CGFloat", @@ -265,7 +265,7 @@ achieve the maximum the swipe possible to the other edge. }, method: "actionForSwipeFastInDirection:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }] }; @@ -286,7 +286,7 @@ achieve maximum the swipe possible to the other edge. }, method: "actionForSwipeSlowInDirection:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }] }; @@ -314,7 +314,7 @@ the specified point. }, method: "actionForSwipeFastInDirection:xOriginStartPercentage:yOriginStartPercentage:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }, { type: "CGFloat", @@ -348,7 +348,7 @@ the specified point. }, method: "actionForSwipeSlowInDirection:xOriginStartPercentage:yOriginStartPercentage:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }, { type: "CGFloat", @@ -378,7 +378,7 @@ direction from the specified point. }, method: "actionForMultiFingerSwipeSlowInDirection:numberOfFingers:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }, { type: "NSInteger", @@ -405,7 +405,7 @@ direction from the specified point. }, method: "actionForMultiFingerSwipeFastInDirection:numberOfFingers:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }, { type: "NSInteger", @@ -434,7 +434,7 @@ direction from the specified point. }, method: "actionForMultiFingerSwipeSlowInDirection:numberOfFingers:xOriginStartPercentage:yOriginStartPercentage:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }, { type: "NSInteger", @@ -469,7 +469,7 @@ direction from the specified point. }, method: "actionForMultiFingerSwipeFastInDirection:numberOfFingers:xOriginStartPercentage:yOriginStartPercentage:", args: [{ - type: "GREYDirection", + type: "NSInteger", value: sanitize_greyDirection(direction) }, { type: "NSInteger", diff --git a/generation/__tests__/__snapshots__/earl-grey.js.snap b/generation/__tests__/__snapshots__/earl-grey.js.snap index d83bb7641b..a44881bf56 100644 --- a/generation/__tests__/__snapshots__/earl-grey.js.snap +++ b/generation/__tests__/__snapshots__/earl-grey.js.snap @@ -69,7 +69,7 @@ exports[`earl-grey generation Invocations should sanitize the directions 1`] = ` Object { "args": Array [ Object { - "type": "GREYDirection", + "type": "NSInteger", "value": 4, }, Object { diff --git a/generation/__tests__/earl-grey.js b/generation/__tests__/earl-grey.js index 0f66ed3475..e3e60d9671 100644 --- a/generation/__tests__/earl-grey.js +++ b/generation/__tests__/earl-grey.js @@ -143,7 +143,7 @@ describe("earl-grey generation", () => { 5 ); - expect(result.args[0].type).toBe("GREYDirection"); + expect(result.args[0].type).toBe("NSInteger"); expect(result.args[0].value).toBe(4); expect(result).toMatchSnapshot(); }); diff --git a/generation/earl-grey/index.js b/generation/earl-grey/index.js index 0efa80fff5..5f58fdacb4 100644 --- a/generation/earl-grey/index.js +++ b/generation/earl-grey/index.js @@ -132,20 +132,33 @@ function createTypeChecks(json) { const callGlobal = sanitizerName => argIdentifier => t.callExpression(t.identifier(sanitizerName), [t.identifier(argIdentifier)]); const supportedContentSanitizersMap = { - GREYDirection: callGlobal("sanitize_greyDirection") + GREYDirection: { + type: 'NSInteger', + value: callGlobal("sanitize_greyDirection"), + }, }; function addArgumentContentSanitizerCall(json) { if (supportedContentSanitizersMap[json.type]) { - return supportedContentSanitizersMap[json.type](json.name); + return supportedContentSanitizersMap[json.type].value(json.name); } return t.identifier(json.name); } +function addArgumentTypeSanitizer(json) { + if (supportedContentSanitizersMap[json.type]) { + return supportedContentSanitizersMap[json.type].type; + } + + return json.type; +} function createReturnStatement(className, json) { const args = json.args.map(arg => t.objectExpression([ - t.objectProperty(t.identifier("type"), t.stringLiteral(arg.type)), + t.objectProperty( + t.identifier("type"), + t.stringLiteral(addArgumentTypeSanitizer(arg)) + ), t.objectProperty( t.identifier("value"), addArgumentContentSanitizerCall(arg)