Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert MountingManagerTest to Kotlin #44837

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.fabric

import com.facebook.react.ReactRootView
import com.facebook.react.bridge.BridgeReactContext
import com.facebook.react.bridge.ReactTestHelper.createMockCatalystInstance
import com.facebook.react.fabric.mounting.MountingManager
import com.facebook.react.fabric.mounting.MountingManager.MountItemExecutor
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests
import com.facebook.react.uimanager.IllegalViewOperationException
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewManager
import com.facebook.react.uimanager.ViewManagerRegistry
import com.facebook.react.views.view.ReactViewManager
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment

/** Tests [FabricUIManager] */
@RunWith(RobolectricTestRunner::class)
class MountingManagerTest {
private lateinit var mountingManager: MountingManager
private lateinit var mountItemExecutor: MountItemExecutor
private lateinit var themedReactContext: ThemedReactContext
private var nextRootTag = 1

@Before
fun setUp() {
ReactNativeFeatureFlagsForTests.setUp()
val reactContext = BridgeReactContext(RuntimeEnvironment.getApplication())
reactContext.initializeWithInstance(createMockCatalystInstance())
themedReactContext = ThemedReactContext(reactContext, reactContext, null, -1)
val viewManagers = listOf<ViewManager<*, *>>(ReactViewManager())
mountItemExecutor = MountItemExecutor {
// no-op
}
mountingManager = MountingManager(ViewManagerRegistry(viewManagers), mountItemExecutor)
}

@Test
fun addRootView() {
val reactRootView = ReactRootView(themedReactContext)
val rootReactTag = nextRootTag++
mountingManager.startSurface(rootReactTag, themedReactContext, reactRootView)
assertThat(reactRootView.id).isEqualTo(rootReactTag)
}

@Test
fun unableToAddRootViewTwice() {
val reactRootView = ReactRootView(themedReactContext)
val rootReactTag = nextRootTag++
mountingManager.startSurface(rootReactTag, themedReactContext, reactRootView)
assertThat(reactRootView.id).isEqualTo(rootReactTag)

// This is now a SoftException because it indicates a race condition in starting
// a single surface with a single View, and is concerning but not necessarily fatal.
// To be clear: in this case we're still guaranteed a single SurfaceMountingManager
// and therefore a single View involved.
mountingManager.startSurface(rootReactTag, themedReactContext, reactRootView)
}

@Test(expected = IllegalViewOperationException::class)
fun unableToAddHandledRootView() {
val reactRootView = ReactRootView(themedReactContext)
reactRootView.id = 1234567
val rootReactTag = nextRootTag++
mountingManager.startSurface(rootReactTag, themedReactContext, reactRootView)
}
}
Loading