Skip to content

Commit

Permalink
converted InteropEventEmitter java file to kotlin (#38144)
Browse files Browse the repository at this point in the history
Summary:
Helping in [Kotlin-ify React Native tests](#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: #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
  • Loading branch information
stanwolverine authored and facebook-github-bot committed Jul 1, 2023
1 parent 81785c2 commit a9bfd7b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 67 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit a9bfd7b

Please sign in to comment.