From 3660b7cf73a322750fb9cc9aa124da0f5e739c80 Mon Sep 17 00:00:00 2001 From: David <4661784+retyui@users.noreply.github.com> Date: Tue, 8 Aug 2023 11:21:19 -0700 Subject: [PATCH] =?UTF-8?q?=E2=98=82=EF=B8=8F=20BaseViewManagerTest.java?= =?UTF-8?q?=20=3D>=20BaseViewManagerTest.kt=20(#38841)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Issue: https://github.com/facebook/react-native/issues/38825#issuecomment-1669202200 ## Changelog: [GENERAL] [CHANGED] - `BaseViewManagerTest.java` => `BaseViewManagerTest.kt` Pull Request resolved: https://github.com/facebook/react-native/pull/38841 Test Plan: ```shell ./gradlew :packages:react-native:ReactAndroid:test ``` Reviewed By: cortinico Differential Revision: D48153909 Pulled By: rshest fbshipit-source-id: cac20a64b72b77c23edb2e20b65717c1a425a08a --- .../react/uimanager/BaseViewManagerTest.java | 88 ------------------- .../react/uimanager/BaseViewManagerTest.kt | 75 ++++++++++++++++ 2 files changed, 75 insertions(+), 88 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.java create mode 100644 packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.kt diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.java deleted file mode 100644 index 35b367e50195e3..00000000000000 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * 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.assertj.core.api.Assertions.assertThat; - -import com.facebook.react.R; -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.JavaOnlyMap; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.ReactAccessibilityDelegate.AccessibilityRole; -import com.facebook.react.uimanager.ReactAccessibilityDelegate.Role; -import com.facebook.react.views.view.ReactViewGroup; -import com.facebook.react.views.view.ReactViewManager; -import java.util.Locale; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.rule.PowerMockRule; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -@PrepareForTest({Arguments.class}) -@RunWith(RobolectricTestRunner.class) -@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "androidx.*", "android.*"}) -@Ignore // TODO T14964130 -public class BaseViewManagerTest { - - @Rule public PowerMockRule rule = new PowerMockRule(); - - private BaseViewManager mViewManager; - private ReactViewGroup mView; - - @Before - public void setUp() { - mViewManager = new ReactViewManager(); - mView = new ReactViewGroup(RuntimeEnvironment.getApplication()); - PowerMockito.mockStatic(Arguments.class); - PowerMockito.when(Arguments.createMap()) - .thenAnswer( - new Answer() { - @Override - public Object answer(InvocationOnMock invocation) throws Throwable { - return new JavaOnlyMap(); - } - }); - } - - @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); - } - - @Test - public void testAccessibilityStateSelected() { - WritableMap accessibilityState = Arguments.createMap(); - accessibilityState.putBoolean("selected", true); - mViewManager.setViewState(mView, accessibilityState); - assertThat(mView.getTag(R.id.accessibility_state)).isEqualTo(accessibilityState); - assertThat(mView.isSelected()).isEqualTo(true); - } - - @Test - public void testRoleList() { - mViewManager.setRole(mView, "list"); - assertThat(mView.getTag(R.id.role)).isEqualTo(Role.LIST); - } -} diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.kt new file mode 100644 index 00000000000000..325354f08a4567 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/BaseViewManagerTest.kt @@ -0,0 +1,75 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * 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 com.facebook.react.R +import com.facebook.react.bridge.Arguments +import com.facebook.react.bridge.JavaOnlyMap +import com.facebook.react.views.view.ReactViewGroup +import com.facebook.react.views.view.ReactViewManager +import java.util.Locale +import org.assertj.core.api.Assertions +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.api.mockito.PowerMockito.mockStatic +import org.powermock.api.mockito.PowerMockito.`when` as whenever +import org.powermock.core.classloader.annotations.PowerMockIgnore +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.rule.PowerMockRule +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment + +@PrepareForTest(Arguments::class) +@RunWith(RobolectricTestRunner::class) +@PowerMockIgnore("org.mockito.*", "org.robolectric.*", "androidx.*", "android.*") +class BaseViewManagerTest { + private lateinit var viewManager: BaseViewManager + private lateinit var view: ReactViewGroup + + @get:Rule var rule = PowerMockRule() + + @Before + fun setUp() { + viewManager = ReactViewManager() + view = ReactViewGroup(RuntimeEnvironment.getApplication()) + mockStatic(Arguments::class.java) + whenever(Arguments.createMap()).thenAnswer { JavaOnlyMap() } + } + + @Test + fun testAccessibilityRoleNone() { + viewManager.setAccessibilityRole(view, "none") + Assertions.assertThat(view.getTag(R.id.accessibility_role)) + .isEqualTo(ReactAccessibilityDelegate.AccessibilityRole.NONE) + } + + @Test + fun testAccessibilityRoleTurkish() { + Locale.setDefault(Locale.forLanguageTag("tr-TR")) + viewManager.setAccessibilityRole(view, "image") + Assertions.assertThat(view.getTag(R.id.accessibility_role)) + .isEqualTo(ReactAccessibilityDelegate.AccessibilityRole.IMAGE) + } + + @Test + fun testAccessibilityStateSelected() { + val accessibilityState = Arguments.createMap() + accessibilityState.putBoolean("selected", true) + viewManager.setViewState(view, accessibilityState) + Assertions.assertThat(view.getTag(R.id.accessibility_state)).isEqualTo(accessibilityState) + Assertions.assertThat(view.isSelected).isEqualTo(true) + } + + @Test + fun testRoleList() { + viewManager.setRole(view, "list") + Assertions.assertThat(view.getTag(R.id.role)).isEqualTo(ReactAccessibilityDelegate.Role.LIST) + } +}