From a6a09a8be0204c90d639657e3155d95b16dfadf1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 20 Aug 2026 16:01:31 +0200 Subject: [PATCH] Move FakeParentNode to the testutils module The fake was declared in RootFlowNodeTest, so other tests could not use it. Move it to the testutils module, in the node package, and make its documentation generic. Co-Authored-By: Claude Opus 5 (1M context) --- .../android/appnav/RootFlowNodeTest.kt | 24 +------------ .../tests/testutils/node/FakeParentNode.kt | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 tests/testutils/src/main/kotlin/io/element/android/tests/testutils/node/FakeParentNode.kt diff --git a/appnav/src/test/kotlin/io/element/android/appnav/RootFlowNodeTest.kt b/appnav/src/test/kotlin/io/element/android/appnav/RootFlowNodeTest.kt index c39b468cac..0916c4f09a 100644 --- a/appnav/src/test/kotlin/io/element/android/appnav/RootFlowNodeTest.kt +++ b/appnav/src/test/kotlin/io/element/android/appnav/RootFlowNodeTest.kt @@ -12,13 +12,8 @@ package io.element.android.appnav import android.content.Intent import android.net.Uri import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier import com.bumble.appyx.core.modality.AncestryInfo import com.bumble.appyx.core.modality.BuildContext -import com.bumble.appyx.core.navigation.model.permanent.PermanentNavModel -import com.bumble.appyx.core.node.Node -import com.bumble.appyx.core.node.ParentNode import com.bumble.appyx.core.node.node import com.bumble.appyx.navmodel.backstack.activeElement import com.bumble.appyx.testing.junit4.util.MainDispatcherRule @@ -42,7 +37,6 @@ import io.element.android.features.share.test.FakeShareIntentHandler import io.element.android.features.signedout.test.FakeSignedOutEntryPoint import io.element.android.libraries.accountselect.test.FakeAccountSelectEntryPoint import io.element.android.libraries.architecture.AssistedNodeFactory -import io.element.android.libraries.di.DependencyInjectionGraphOwner import io.element.android.libraries.featureflag.test.FakeFeatureFlagService import io.element.android.libraries.matrix.test.FakeSdkMetadata import io.element.android.libraries.matrix.test.auth.FakeMatrixAuthenticationService @@ -57,6 +51,7 @@ import io.element.android.services.analytics.test.FakeAnalyticsService import io.element.android.services.analytics.test.watchers.FakeAnalyticsColdStartWatcher import io.element.android.services.apperror.test.FakeAppErrorStateService import io.element.android.tests.testutils.node.FakeNodeFactoriesBindings +import io.element.android.tests.testutils.node.FakeParentNode import io.element.android.tests.testutils.presenter.NotUsedPresenter import io.element.android.tests.testutils.robolectric.RobolectricTest import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -192,20 +187,3 @@ private val A_LOGIN_ENTRY_POINT_PARAMS = LoginEntryPoint.Params( accountProvider = A_LOGIN_PARAMS.accountProvider, loginHint = A_LOGIN_PARAMS.loginHint, ) - -/** - * [RootFlowNode] creates its children using the dependency injection graph of its ancestors, so it needs a parent - * owning a graph able to create a [NotLoggedInFlowNode]. - */ -private class FakeParentNode( - override val graph: Any, -) : ParentNode( - navModel = PermanentNavModel(navTargets = setOf(Unit), savedStateMap = null), - buildContext = BuildContext.root(savedStateMap = null), -), - DependencyInjectionGraphOwner { - override fun resolve(navTarget: Unit, buildContext: BuildContext): Node = node(buildContext) {} - - @Composable - override fun View(modifier: Modifier) = Unit -} diff --git a/tests/testutils/src/main/kotlin/io/element/android/tests/testutils/node/FakeParentNode.kt b/tests/testutils/src/main/kotlin/io/element/android/tests/testutils/node/FakeParentNode.kt new file mode 100644 index 0000000000..1375043d48 --- /dev/null +++ b/tests/testutils/src/main/kotlin/io/element/android/tests/testutils/node/FakeParentNode.kt @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2026 Element Creations Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.tests.testutils.node + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import com.bumble.appyx.core.modality.BuildContext +import com.bumble.appyx.core.navigation.model.permanent.PermanentNavModel +import com.bumble.appyx.core.node.Node +import com.bumble.appyx.core.node.ParentNode +import com.bumble.appyx.core.node.node +import io.element.android.libraries.di.DependencyInjectionGraphOwner + +/** + * A Node creates its children using the dependency injection graph of its ancestors, so a Node under test + * needs such a parent to be able to create its children. + */ +class FakeParentNode( + override val graph: Any, +) : ParentNode( + navModel = PermanentNavModel(navTargets = setOf(Unit), savedStateMap = null), + buildContext = BuildContext.root(savedStateMap = null), +), + DependencyInjectionGraphOwner { + override fun resolve(navTarget: Unit, buildContext: BuildContext): Node = node(buildContext) {} + + @Composable + override fun View(modifier: Modifier) = Unit +}