Use tag ids for testID

Summary: View tags are currently used for end-to-end test IDs. We'd like to overload the tag field with other information such as nativeID (for native refs) and transitionID (for shared element transitions) in the future. Added a key for testID's tag

Reviewed By: AaaChiuuu

Differential Revision: D4833045

fbshipit-source-id: c2f9371c9a3dbb2411e114f4f096f723ac3132c0
This commit is contained in:
Andrew Y. Chen 2017-04-05 12:19:50 -07:00 committed by Facebook Github Bot
parent da43c297f4
commit 3bf367cbb7
7 changed files with 28 additions and 5 deletions

View File

@ -248,7 +248,7 @@ android {
sourceSets.main { sourceSets.main {
jni.srcDirs = [] jni.srcDirs = []
jniLibs.srcDir "$buildDir/react-ndk/exported" jniLibs.srcDir "$buildDir/react-ndk/exported"
res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell', 'src/main/res/views/modal'] res.srcDirs = ['src/main/res/devsupport', 'src/main/res/shell', 'src/main/res/views/modal', 'src/main/res/views/uimanager']
java { java {
srcDirs = ['src/main/java', 'src/main/libraries/soloader/java', 'src/main/jni/first-party/fb/jni/java'] srcDirs = ['src/main/java', 'src/main/libraries/soloader/java', 'src/main/jni/first-party/fb/jni/java']
exclude 'com/facebook/react/processing' exclude 'com/facebook/react/processing'

View File

@ -21,6 +21,8 @@ android_library(
react_native_dep("third-party/java/junit:junit"), react_native_dep("third-party/java/junit:junit"),
react_native_dep("third-party/java/mockito:mockito"), react_native_dep("third-party/java/mockito:mockito"),
react_native_dep("third-party/java/testing-support-lib:runner"), react_native_dep("third-party/java/testing-support-lib:runner"),
react_native_integration_tests_target("java/com/facebook/react/testing/idledetection:idledetection"),
react_native_integration_tests_target("java/com/facebook/react/testing/network:network"),
react_native_target("java/com/facebook/react:react"), react_native_target("java/com/facebook/react:react"),
react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/common:common"),
@ -32,7 +34,6 @@ android_library(
react_native_target("java/com/facebook/react/modules/debug:interfaces"), react_native_target("java/com/facebook/react/modules/debug:interfaces"),
react_native_target("java/com/facebook/react/shell:shell"), react_native_target("java/com/facebook/react/shell:shell"),
react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_integration_tests_target("java/com/facebook/react/testing/idledetection:idledetection"), react_native_target("res:uimanager"),
react_native_integration_tests_target("java/com/facebook/react/testing/network:network"),
], ],
) )

View File

@ -17,6 +17,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.facebook.react.NativeModuleRegistryBuilder; import com.facebook.react.NativeModuleRegistryBuilder;
import com.facebook.react.R;
import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactInstanceManagerBuilder; import com.facebook.react.ReactInstanceManagerBuilder;
import com.facebook.react.bridge.CatalystInstance; import com.facebook.react.bridge.CatalystInstance;
@ -187,7 +188,9 @@ public class ReactTestHelper {
} }
public static String getTestId(View view) { public static String getTestId(View view) {
return view.getTag() instanceof String ? (String) view.getTag() : null; return view.getTag(R.id.react_test_id) instanceof String
? (String) view.getTag(R.id.react_test_id)
: null;
} }
private static View findChild(View root, Predicate<View> predicate) { private static View findChild(View root, Predicate<View> predicate) {
@ -211,7 +214,7 @@ public class ReactTestHelper {
return new Predicate<View>() { return new Predicate<View>() {
@Override @Override
public boolean apply(View view) { public boolean apply(View view) {
Object tag = view.getTag(); Object tag = getTestId(view);
return tag != null && tag.equals(tagValue); return tag != null && tag.equals(tagValue);
} }
}; };

View File

@ -26,5 +26,6 @@ android_library(
react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"), react_native_target("java/com/facebook/react/modules/i18nmanager:i18nmanager"),
react_native_target("java/com/facebook/react/touch:touch"), react_native_target("java/com/facebook/react/touch:touch"),
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
react_native_target("res:uimanager"),
], ],
) )

View File

@ -5,6 +5,7 @@ package com.facebook.react.uimanager;
import android.graphics.Color; import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.view.View; import android.view.View;
import com.facebook.react.R;
import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactProp;
@ -85,6 +86,9 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
@ReactProp(name = PROP_TEST_ID) @ReactProp(name = PROP_TEST_ID)
public void setTestId(T view, String testId) { public void setTestId(T view, String testId) {
view.setTag(R.id.react_test_id, testId);
// temporarily set the tag and keyed tags to avoid end to end test regressions
view.setTag(testId); view.setTag(testId);
} }

View File

@ -27,4 +27,13 @@ android_resource(
], ],
) )
android_resource(
name = "uimanager",
package = "com.facebook.react",
res = "views/uimanager",
visibility = [
"PUBLIC",
],
)
# New resource directories must be added to react-native-github/ReactAndroid/build.gradle # New resource directories must be added to react-native-github/ReactAndroid/build.gradle

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- tag is used to store the testID tag -->
<item type="id" name="react_test_id"/>
</resources>