Skip to content

Commit

Permalink
Use tag ids for testID
Browse files Browse the repository at this point in the history
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: D4770368

fbshipit-source-id: b76c53a20520aac1b25d435b6d5eb809e8833675
  • Loading branch information
ayc1 authored and facebook-github-bot committed Apr 4, 2017
1 parent 67e54f8 commit 77c19cc
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ android_library(
react_native_dep("third-party/java/junit:junit"),
react_native_dep("third-party/java/mockito:mockito"),
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/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
Expand All @@ -32,7 +34,6 @@ android_library(
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/uimanager:uimanager"),
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("res:uimanager"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.view.ViewGroup;

import com.facebook.react.NativeModuleRegistryBuilder;
import com.facebook.react.R;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactInstanceManagerBuilder;
import com.facebook.react.bridge.CatalystInstance;
Expand Down Expand Up @@ -187,7 +188,9 @@ public static View getViewWithReactTestId(View rootView, String testId) {
}

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) {
Expand All @@ -211,7 +214,7 @@ private static Predicate<View> hasTagValue(final String tagValue) {
return new Predicate<View>() {
@Override
public boolean apply(View view) {
Object tag = view.getTag();
Object tag = getTestId(view);
return tag != null && tag.equals(tagValue);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ android_library(
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/uimanager/annotations:annotations"),
react_native_target("res:uimanager"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import com.facebook.react.R;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.annotations.ReactProp;

Expand Down Expand Up @@ -85,6 +86,9 @@ public void setRenderToHardwareTexture(T view, boolean useHWTexture) {

@ReactProp(name = PROP_TEST_ID)
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);
}

Expand Down
9 changes: 9 additions & 0 deletions ReactAndroid/src/main/res/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ android_resource(
"PUBLIC",
],
)

android_resource(
name = "uimanager",
package = "com.facebook.react",
res = "views/uimanager",
visibility = [
"PUBLIC",
],
)
5 changes: 5 additions & 0 deletions ReactAndroid/src/main/res/views/uimanager/values/ids.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 77c19cc

Please sign in to comment.