Add test on DefaultSpaceEntryPoint
This commit is contained in:
parent
ba51b29d23
commit
a69cf58a5b
5 changed files with 115 additions and 4 deletions
|
|
@ -37,7 +37,7 @@ class SpacePresenter(
|
||||||
private val seenInvitesStore: SeenInvitesStore,
|
private val seenInvitesStore: SeenInvitesStore,
|
||||||
) : Presenter<SpaceState> {
|
) : Presenter<SpaceState> {
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
interface Factory {
|
fun interface Factory {
|
||||||
fun create(inputs: SpaceEntryPoint.Inputs): SpacePresenter
|
fun create(inputs: SpaceEntryPoint.Inputs): SpacePresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2025 New Vector 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.features.space.impl
|
||||||
|
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import com.bumble.appyx.core.modality.BuildContext
|
||||||
|
import com.google.common.truth.Truth.assertThat
|
||||||
|
import io.element.android.features.invite.test.InMemorySeenInvitesStore
|
||||||
|
import io.element.android.features.space.api.SpaceEntryPoint
|
||||||
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
import io.element.android.libraries.matrix.test.A_ROOM_ID
|
||||||
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
|
import io.element.android.libraries.matrix.test.spaces.FakeSpaceRoomList
|
||||||
|
import io.element.android.libraries.matrix.test.spaces.FakeSpaceService
|
||||||
|
import io.element.android.tests.testutils.lambda.lambdaError
|
||||||
|
import io.element.android.tests.testutils.node.TestParentNode
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class DefaultSpaceEntryPointTest {
|
||||||
|
@Test
|
||||||
|
fun `test DefaultSpaceEntryPoint`() {
|
||||||
|
val entryPoint = DefaultSpaceEntryPoint()
|
||||||
|
val nodeInputs = SpaceEntryPoint.Inputs(A_ROOM_ID)
|
||||||
|
val parentNode = TestParentNode.create { buildContext, plugins ->
|
||||||
|
SpaceNode(
|
||||||
|
buildContext = buildContext,
|
||||||
|
plugins = plugins,
|
||||||
|
presenterFactory = { inputs ->
|
||||||
|
assertThat(inputs).isEqualTo(nodeInputs)
|
||||||
|
SpacePresenter(
|
||||||
|
inputs = inputs,
|
||||||
|
client = FakeMatrixClient(
|
||||||
|
spaceService = FakeSpaceService(
|
||||||
|
spaceRoomListResult = { FakeSpaceRoomList() },
|
||||||
|
)
|
||||||
|
),
|
||||||
|
seenInvitesStore = InMemorySeenInvitesStore(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val callback = object : SpaceEntryPoint.Callback {
|
||||||
|
override fun onOpenRoom(roomId: RoomId) {
|
||||||
|
lambdaError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val result = entryPoint.nodeBuilder(parentNode, BuildContext.root(null))
|
||||||
|
.inputs(nodeInputs)
|
||||||
|
.callback(callback)
|
||||||
|
.build()
|
||||||
|
assertThat(result).isInstanceOf(SpaceNode::class.java)
|
||||||
|
assertThat(result.plugins).contains(nodeInputs)
|
||||||
|
assertThat(result.plugins).contains(callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,6 +11,6 @@ import com.bumble.appyx.core.modality.BuildContext
|
||||||
import com.bumble.appyx.core.node.Node
|
import com.bumble.appyx.core.node.Node
|
||||||
import com.bumble.appyx.core.plugin.Plugin
|
import com.bumble.appyx.core.plugin.Plugin
|
||||||
|
|
||||||
interface AssistedNodeFactory<NODE : Node> {
|
fun interface AssistedNodeFactory<NODE : Node> {
|
||||||
fun create(buildContext: BuildContext, plugins: List<Plugin>): NODE
|
fun create(buildContext: BuildContext, plugins: List<Plugin>): NODE
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,7 @@ inline fun <reified N : Node> NodeFactoriesBindings.createNode(
|
||||||
return node as N
|
return node as N
|
||||||
}
|
}
|
||||||
|
|
||||||
// @BindingContainer
|
fun interface NodeFactoriesBindings {
|
||||||
interface NodeFactoriesBindings {
|
|
||||||
@Multibinds
|
@Multibinds
|
||||||
fun nodeFactories(): Map<KClass<out Node>, AssistedNodeFactory<*>>
|
fun nodeFactories(): Map<KClass<out Node>, AssistedNodeFactory<*>>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2025 New Vector 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 com.bumble.appyx.core.modality.BuildContext
|
||||||
|
import com.bumble.appyx.core.node.EmptyNodeView
|
||||||
|
import com.bumble.appyx.core.node.Node
|
||||||
|
import com.bumble.appyx.core.plugin.Plugin
|
||||||
|
import io.element.android.libraries.architecture.AssistedNodeFactory
|
||||||
|
import io.element.android.libraries.architecture.NodeFactoriesBindings
|
||||||
|
import io.element.android.libraries.di.DependencyInjectionGraphOwner
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A parent Node that can create a single type of child Node using the provided factory.
|
||||||
|
* This is useful to test a Feature entry point, by providing a fake parent that can create a
|
||||||
|
* child Node.
|
||||||
|
*/
|
||||||
|
class TestParentNode<Child : Node>(
|
||||||
|
private val childNodeClass: KClass<out Node>,
|
||||||
|
private val childNodeFactory: (buildContext: BuildContext, plugins: List<Plugin>) -> Child,
|
||||||
|
) : DependencyInjectionGraphOwner,
|
||||||
|
Node(
|
||||||
|
buildContext = BuildContext.Companion.root(savedStateMap = null),
|
||||||
|
plugins = emptyList(),
|
||||||
|
view = EmptyNodeView,
|
||||||
|
) {
|
||||||
|
|
||||||
|
override val graph: NodeFactoriesBindings = NodeFactoriesBindings {
|
||||||
|
mapOf(
|
||||||
|
childNodeClass to AssistedNodeFactory { buildContext, plugins ->
|
||||||
|
childNodeFactory(buildContext, plugins)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Inline factory function with reified type parameter
|
||||||
|
inline fun <reified Child : Node> create(
|
||||||
|
noinline childNodeFactory: (buildContext: BuildContext, plugins: List<Plugin>) -> Child,
|
||||||
|
): TestParentNode<Child> {
|
||||||
|
return TestParentNode(Child::class, childNodeFactory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue