mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Convert UIManagerModuleConstantsHelperTest to Kotlin (#37732)
Summary: Converts UIManagerModuleConstantsHelperTest from Java to Kotlin, as per issue https://github.com/facebook/react-native/issues/37708 ## Changelog: [Internal] [Changed] - Convert UIManagerModuleConstantsHelperTest to Kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/37732 Test Plan: Tests pass: `./gradlew :packages:react-native:ReactAndroid:test` Formatted with [KtFmt](https://facebook.github.io/ktfmt/) Reviewed By: cortinico Differential Revision: D46493160 Pulled By: mdvacca fbshipit-source-id: c7522c016e0ef36b12d1b77f37171a72c188edd0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
29ee917a0e
commit
84a3b898d5
-89
@@ -1,89 +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.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.facebook.react.common.MapBuilder;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UIManagerModuleConstantsHelperTest {
|
||||
|
||||
@Test
|
||||
public void normalizeEventTypes_withNull_doesNothing() {
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeEventTypes_withEmptyMap_doesNothing() {
|
||||
Map<Object, Object> emptyMap = MapBuilder.builder().build();
|
||||
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(emptyMap);
|
||||
|
||||
assertTrue(emptyMap.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeEventTypes_withOnEvent_doesNormalize() {
|
||||
Map<Object, Object> onClickMap = MapBuilder.builder().put("onClick", "¯\\_(ツ)_/¯").build();
|
||||
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(onClickMap);
|
||||
|
||||
assertTrue(onClickMap.containsKey("topOnClick"));
|
||||
assertTrue(onClickMap.containsKey("onClick"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeEventTypes_withTopEvent_doesNormalize() {
|
||||
Map<Object, Object> onClickMap = MapBuilder.builder().put("topOnClick", "¯\\_(ツ)_/¯").build();
|
||||
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(onClickMap);
|
||||
|
||||
assertTrue(onClickMap.containsKey("topOnClick"));
|
||||
assertFalse(onClickMap.containsKey("onClick"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void normalizeEventTypes_withNestedObjects_doesNotLoseThem() {
|
||||
Map<String, Object> nestedObjects =
|
||||
MapBuilder.<String, Object>builder()
|
||||
.put(
|
||||
"onColorChanged",
|
||||
MapBuilder.of(
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of(
|
||||
"bubbled", "onColorChanged", "captured", "onColorChangedCapture")))
|
||||
.build();
|
||||
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(nestedObjects);
|
||||
|
||||
assertTrue(nestedObjects.containsKey("topOnColorChanged"));
|
||||
Map<String, Object> innerMap = (Map<String, Object>) nestedObjects.get("topOnColorChanged");
|
||||
assertNotNull(innerMap);
|
||||
assertTrue(innerMap.containsKey("phasedRegistrationNames"));
|
||||
Map<String, Object> innerInnerMap =
|
||||
(Map<String, Object>) innerMap.get("phasedRegistrationNames");
|
||||
assertNotNull(innerInnerMap);
|
||||
assertEquals("onColorChanged", innerInnerMap.get("bubbled"));
|
||||
assertEquals("onColorChangedCapture", innerInnerMap.get("captured"));
|
||||
|
||||
assertTrue(nestedObjects.containsKey("onColorChanged"));
|
||||
innerMap = (Map<String, Object>) nestedObjects.get("topOnColorChanged");
|
||||
assertNotNull(innerMap);
|
||||
assertTrue(innerMap.containsKey("phasedRegistrationNames"));
|
||||
innerInnerMap = (Map<String, Object>) innerMap.get("phasedRegistrationNames");
|
||||
assertNotNull(innerInnerMap);
|
||||
assertEquals("onColorChanged", innerInnerMap.get("bubbled"));
|
||||
assertEquals("onColorChangedCapture", innerInnerMap.get("captured"));
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.common.MapBuilder
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class UIManagerModuleConstantsHelperTest {
|
||||
@Test
|
||||
fun normalizeEventTypes_withNull_doesNothing() {
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalizeEventTypes_withEmptyMap_doesNothing() {
|
||||
val emptyMap: Map<String, Any?> = MapBuilder.builder<String, Any?>().build()
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(emptyMap)
|
||||
assertTrue(emptyMap.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalizeEventTypes_withOnEvent_doesNormalize() {
|
||||
val onClickMap: Map<String, String> =
|
||||
MapBuilder.builder<String, String>().put("onClick", "¯\\_(ツ)_/¯").build()
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(onClickMap)
|
||||
assertTrue(onClickMap.containsKey("topOnClick"))
|
||||
assertTrue(onClickMap.containsKey("onClick"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun normalizeEventTypes_withTopEvent_doesNormalize() {
|
||||
val onClickMap: Map<String, String> =
|
||||
MapBuilder.builder<String, String>().put("topOnClick", "¯\\_(ツ)_/¯").build()
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(onClickMap)
|
||||
assertTrue(onClickMap.containsKey("topOnClick"))
|
||||
assertFalse(onClickMap.containsKey("onClick"))
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@Test
|
||||
fun normalizeEventTypes_withNestedObjects_doesNotLoseThem() {
|
||||
val nestedObjects: Map<String, Any?> =
|
||||
MapBuilder.builder<String, Any?>()
|
||||
.put(
|
||||
"onColorChanged",
|
||||
MapBuilder.of<String, Any?>(
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of<String, String>(
|
||||
"bubbled", "onColorChanged", "captured", "onColorChangedCapture")))
|
||||
.build()
|
||||
UIManagerModuleConstantsHelper.normalizeEventTypes(nestedObjects)
|
||||
assertTrue(nestedObjects.containsKey("topOnColorChanged"))
|
||||
var innerMap = nestedObjects["topOnColorChanged"] as? Map<String, Any?>
|
||||
assertNotNull(innerMap)
|
||||
assertTrue(innerMap!!.containsKey("phasedRegistrationNames"))
|
||||
var innerInnerMap = innerMap.get("phasedRegistrationNames") as? Map<String, Any?>
|
||||
assertNotNull(innerInnerMap)
|
||||
assertEquals("onColorChanged", innerInnerMap!!.get("bubbled"))
|
||||
assertEquals("onColorChangedCapture", innerInnerMap.get("captured"))
|
||||
assertTrue(nestedObjects.containsKey("onColorChanged"))
|
||||
innerMap = nestedObjects.get("topOnColorChanged") as? Map<String, Any?>
|
||||
assertNotNull(innerMap)
|
||||
assertTrue(innerMap!!.containsKey("phasedRegistrationNames"))
|
||||
innerInnerMap = innerMap.get("phasedRegistrationNames") as? Map<String, Any?>
|
||||
assertNotNull(innerInnerMap)
|
||||
assertEquals("onColorChanged", innerInnerMap!!.get("bubbled"))
|
||||
assertEquals("onColorChangedCapture", innerInnerMap.get("captured"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user