mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
converted InteropEventEmitter java file to kotlin (#38144)
Summary: Helping in [Kotlin-ify React Native tests](https://github.com/facebook/react-native/issues/37708), Converted [react/fabric/interop/InteropEventEmitterTest.java](https://github.com/facebook/react-native/tree/main/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/interop/InteropEventEmitterTest.java) to kotlin file ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [INTERNAL] [CHANGED] - `InteropEventEmitterTest.java` file migrated from java to kotlin Pull Request resolved: https://github.com/facebook/react-native/pull/38144 Test Plan: Tests should pass ``` ./gradlew :packages:react-native:ReactAndroid:test ``` Reviewed By: NickGerleman Differential Revision: D47165007 Pulled By: mdvacca fbshipit-source-id: 459b0867810eb1b782eea354d74152306b9546ff
This commit is contained in:
committed by
Facebook GitHub Bot
parent
81785c241e
commit
a9bfd7bb70
-67
@@ -1,67 +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.fabric.interop;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import com.facebook.react.bridge.JavaOnlyMap;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class InteropEventEmitterTest {
|
||||
|
||||
ReactContext mReactContext;
|
||||
FakeEventDispatcher mEventDispatcher;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mReactContext = new ReactApplicationContext(RuntimeEnvironment.application);
|
||||
mEventDispatcher = new FakeEventDispatcher();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveEvent_dispatchesCorrectly() {
|
||||
InteropEventEmitter eventEmitter = new InteropEventEmitter(mReactContext);
|
||||
eventEmitter.overrideEventDispatcher(mEventDispatcher);
|
||||
|
||||
eventEmitter.receiveEvent(42, "onTest", null);
|
||||
|
||||
assertEquals(1, mEventDispatcher.getRecordedDispatchedEvents().size());
|
||||
assertEquals("onTest", mEventDispatcher.getRecordedDispatchedEvents().get(0).getEventName());
|
||||
assertEquals(
|
||||
InteropEvent.class, mEventDispatcher.getRecordedDispatchedEvents().get(0).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveEvent_dataIsPreserved() {
|
||||
InteropEventEmitter eventEmitter = new InteropEventEmitter(mReactContext);
|
||||
eventEmitter.overrideEventDispatcher(mEventDispatcher);
|
||||
WritableMap eventData = JavaOnlyMap.of("color", "indigo");
|
||||
|
||||
eventEmitter.receiveEvent(42, "onTest", eventData);
|
||||
|
||||
InteropEvent event = (InteropEvent) mEventDispatcher.getRecordedDispatchedEvents().get(0);
|
||||
WritableMap dispatchedEventData = event.getEventData();
|
||||
assertNotNull(dispatchedEventData);
|
||||
assertEquals("indigo", dispatchedEventData.getString("color"));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void receiveTouches_isNotSupported() {
|
||||
InteropEventEmitter eventEmitter = new InteropEventEmitter(mReactContext);
|
||||
eventEmitter.receiveTouches("a touch", null, null);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.fabric.interop
|
||||
|
||||
import com.facebook.react.bridge.JavaOnlyMap
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
import com.facebook.react.bridge.ReactContext
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class InteropEventEmitterTest {
|
||||
lateinit var reactContext: ReactContext
|
||||
lateinit var eventDispatcher: FakeEventDispatcher
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
reactContext = ReactApplicationContext(RuntimeEnvironment.application)
|
||||
eventDispatcher = FakeEventDispatcher()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun receiveEvent_dispatchesCorrectly() {
|
||||
val eventEmitter = InteropEventEmitter(reactContext)
|
||||
eventEmitter.overrideEventDispatcher(eventDispatcher)
|
||||
|
||||
eventEmitter.receiveEvent(42, "onTest", null)
|
||||
|
||||
assertEquals(1, eventDispatcher.getRecordedDispatchedEvents().size)
|
||||
assertEquals("onTest", eventDispatcher.getRecordedDispatchedEvents().get(0).getEventName())
|
||||
assertEquals(InteropEvent::class, eventDispatcher.getRecordedDispatchedEvents().get(0)::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun receiveEvent_dataIsPreserved() {
|
||||
val eventEmitter = InteropEventEmitter(reactContext)
|
||||
eventEmitter.overrideEventDispatcher(eventDispatcher)
|
||||
val eventData = JavaOnlyMap.of("color", "indigo")
|
||||
|
||||
eventEmitter.receiveEvent(42, "onTest", eventData)
|
||||
|
||||
val event = eventDispatcher.getRecordedDispatchedEvents().get(0) as InteropEvent
|
||||
val dispatchedEventData = event.getEventData()
|
||||
assertNotNull(dispatchedEventData)
|
||||
assertEquals("indigo", dispatchedEventData!!.getString("color"))
|
||||
}
|
||||
|
||||
@Test(expected = java.lang.UnsupportedOperationException::class)
|
||||
fun receiveTouches_isNotSupported() {
|
||||
val eventEmitter = InteropEventEmitter(reactContext)
|
||||
eventEmitter.receiveTouches("a touch", null, null)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user