forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LOCAL] Fabric Interop - Properly dispatch integer commands (facebook…
…#38527) (facebook#38835) resolved: facebook#38527
- Loading branch information
Showing
4 changed files
with
126 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/FabricUIManagerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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 | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.uimanager.ViewManagerRegistry | ||
import com.facebook.react.uimanager.events.BatchEventDispatchedListener | ||
import com.facebook.testutils.fakes.FakeBatchEventDispatchedListener | ||
import com.facebook.testutils.shadows.ShadowSoLoader | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.RuntimeEnvironment | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(shadows = [ShadowSoLoader::class]) | ||
class FabricUIManagerTest { | ||
|
||
private lateinit var reactContext: ReactApplicationContext | ||
private lateinit var viewManagerRegistry: ViewManagerRegistry | ||
private lateinit var batchEventDispatchedListener: BatchEventDispatchedListener | ||
private lateinit var underTest: FabricUIManager | ||
|
||
@Before | ||
fun setup() { | ||
reactContext = ReactApplicationContext(RuntimeEnvironment.getApplication()) | ||
viewManagerRegistry = ViewManagerRegistry(emptyList()) | ||
batchEventDispatchedListener = FakeBatchEventDispatchedListener() | ||
underTest = FabricUIManager(reactContext, viewManagerRegistry, batchEventDispatchedListener) | ||
} | ||
|
||
@Test | ||
fun createDispatchCommandMountItemForInterop_withValidString_returnsStringEvent() { | ||
val command = underTest.createDispatchCommandMountItemForInterop(11, 1, "anEvent", null) | ||
|
||
// DispatchStringCommandMountItem is package private so we can `as` check it. | ||
val className = command::class.java.name.substringAfterLast(".") | ||
assertEquals("DispatchStringCommandMountItem", className) | ||
} | ||
|
||
@Test | ||
fun createDispatchCommandMountItemForInterop_withValidInt_returnsIntEvent() { | ||
val command = underTest.createDispatchCommandMountItemForInterop(11, 1, "42", null) | ||
|
||
// DispatchIntCommandMountItem is package private so we can `as` check it. | ||
val className = command::class.java.name.substringAfterLast(".") | ||
assertEquals("DispatchIntCommandMountItem", className) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...actAndroid/src/test/java/com/facebook/testutils/fakes/FakeBatchEventDispatchedListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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.testutils.fakes | ||
|
||
import com.facebook.react.uimanager.events.BatchEventDispatchedListener | ||
|
||
/** A fake [BatchEventDispatchedListener] for testing that does nothing. */ | ||
class FakeBatchEventDispatchedListener : BatchEventDispatchedListener { | ||
override fun onBatchEventDispatched() { | ||
// do nothing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters