Fix accessibilityRole value lookup

Summary:
Accessibility roles are enums that are looked up by matching a string accessibility role from JS to the enum's name using .toUpperCase(). .toUpperCase() causes issues in certain languages such as Turkish because the "i"s translate to "?".

D9402330 tried to address this by forcing the .toUpperCase to use Locale.US, but now it sometimes translates to "?"

Use .equalsIgnoreCase() instead to avoid translations.

Reviewed By: mdvacca, mmmulani

Differential Revision: D9497494

fbshipit-source-id: 0f8b7f2071b08ccb86655fee7bfd2d009ddde8eb
This commit is contained in:
Andrew Chen (Eng)
2018-08-24 13:03:34 -07:00
committed by Facebook Github Bot
parent 47dc31d464
commit 1f96ff62cf
4 changed files with 61 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ rn_robolectric_test(
# TODO Disabled temporarily until Yoga linking is fixed t14964130
# srcs = glob(['**/*.java']),
srcs = [
"BaseViewManagerTest.java",
"MatrixMathHelperTest.java",
"SimpleViewPropertyTest.java",
],
@@ -33,6 +34,7 @@ rn_robolectric_test(
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
react_native_target("java/com/facebook/react/views/text:text"),
react_native_target("java/com/facebook/react/views/view:view"),
react_native_target("res:uimanager"),
react_native_tests_target("java/com/facebook/react/bridge:testhelpers"),
],
)

View File

@@ -0,0 +1,50 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.uimanager;
import static org.mockito.Mockito.mock;
import android.content.Context;
import android.support.v4.view.ViewCompat;
import com.facebook.react.uimanager.AccessibilityDelegateUtil.AccessibilityRole;
import com.facebook.react.views.view.ReactViewGroup;
import com.facebook.react.views.view.ReactViewManager;
import com.facebook.react.R;
import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.RobolectricTestRunner;
import static org.fest.assertions.api.Assertions.assertThat;
@RunWith(RobolectricTestRunner.class)
public class BaseViewManagerTest {
private BaseViewManager mViewManager;
private ReactViewGroup mView;
@Before
public void setUp() {
mViewManager = new ReactViewManager();
mView = new ReactViewGroup(RuntimeEnvironment.application);
}
@Test
public void testAccessibilityRoleNone() {
mViewManager.setAccessibilityRole(mView, "none");
assertThat(mView.getTag(R.id.accessibility_role)).isEqualTo(AccessibilityRole.NONE);
}
@Test
public void testAccessibilityRoleTurkish() {
Locale.setDefault(Locale.forLanguageTag("tr-TR"));
mViewManager.setAccessibilityRole(mView, "image");
assertThat(mView.getTag(R.id.accessibility_role)).isEqualTo(AccessibilityRole.IMAGE);
}
}