Add test on DefaultEntryPoints
This commit is contained in:
@@ -47,7 +47,7 @@ class CreatePollPresenter(
|
||||
@Assisted private val timelineMode: Timeline.Mode,
|
||||
) : Presenter<CreatePollState> {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun interface Factory {
|
||||
fun create(
|
||||
timelineMode: Timeline.Mode,
|
||||
backNavigator: () -> Unit,
|
||||
|
||||
@@ -33,7 +33,7 @@ class PollRepository(
|
||||
@Assisted private val timelineMode: Timeline.Mode,
|
||||
) {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun interface Factory {
|
||||
fun create(
|
||||
timelineMode: Timeline.Mode,
|
||||
): PollRepository
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.poll.impl.create
|
||||
|
||||
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.messages.test.FakeMessageComposerContext
|
||||
import io.element.android.features.poll.api.create.CreatePollEntryPoint
|
||||
import io.element.android.features.poll.api.create.CreatePollMode
|
||||
import io.element.android.features.poll.impl.data.PollRepository
|
||||
import io.element.android.libraries.matrix.api.timeline.Timeline
|
||||
import io.element.android.libraries.matrix.test.room.FakeJoinedRoom
|
||||
import io.element.android.libraries.matrix.test.timeline.LiveTimelineProvider
|
||||
import io.element.android.services.analytics.test.FakeAnalyticsService
|
||||
import io.element.android.tests.testutils.node.TestParentNode
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class DefaultCreatePollEntryPointTest {
|
||||
@Test
|
||||
fun `test node builder`() {
|
||||
val entryPoint = DefaultCreatePollEntryPoint()
|
||||
val parentNode = TestParentNode.create { buildContext, plugins ->
|
||||
CreatePollNode(
|
||||
buildContext = buildContext,
|
||||
plugins = plugins,
|
||||
presenterFactory = { timelineMode: Timeline.Mode, backNavigator: () -> Unit, mode: CreatePollMode ->
|
||||
CreatePollPresenter(
|
||||
repositoryFactory = {
|
||||
val room = FakeJoinedRoom()
|
||||
PollRepository(room, LiveTimelineProvider(room), timelineMode)
|
||||
},
|
||||
analyticsService = FakeAnalyticsService(),
|
||||
messageComposerContext = FakeMessageComposerContext(),
|
||||
navigateUp = backNavigator,
|
||||
mode = mode,
|
||||
timelineMode = timelineMode,
|
||||
)
|
||||
},
|
||||
analyticsService = FakeAnalyticsService(),
|
||||
)
|
||||
}
|
||||
val params = CreatePollEntryPoint.Params(
|
||||
timelineMode = Timeline.Mode.Live,
|
||||
mode = CreatePollMode.NewPoll,
|
||||
)
|
||||
val result = entryPoint.nodeBuilder(parentNode, BuildContext.root(null))
|
||||
.params(params)
|
||||
.build()
|
||||
assertThat(result).isInstanceOf(CreatePollNode::class.java)
|
||||
assertThat(result.plugins).contains(CreatePollNode.Inputs(timelineMode = params.timelineMode, mode = params.mode))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.poll.impl.history
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.features.poll.api.create.CreatePollEntryPoint
|
||||
import io.element.android.tests.testutils.lambda.lambdaError
|
||||
import io.element.android.tests.testutils.node.TestParentNode
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class DefaultPollHistoryEntryPointTest {
|
||||
@Test
|
||||
fun `test node builder`() = runTest {
|
||||
val entryPoint = DefaultPollHistoryEntryPoint()
|
||||
val parentNode = TestParentNode.create { buildContext, plugins ->
|
||||
PollHistoryFlowNode(
|
||||
buildContext = buildContext,
|
||||
plugins = plugins,
|
||||
createPollEntryPoint = object : CreatePollEntryPoint {
|
||||
override fun nodeBuilder(parentNode: Node, buildContext: BuildContext) = lambdaError()
|
||||
}
|
||||
)
|
||||
}
|
||||
val result = entryPoint.createNode(parentNode, BuildContext.root(null))
|
||||
assertThat(result).isInstanceOf(PollHistoryFlowNode::class.java)
|
||||
}
|
||||
}
|
||||
@@ -151,23 +151,23 @@ class PollHistoryPresenterTest {
|
||||
assert(paginateLambda).isCalledExactly(2)
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestScope.createPollHistoryPresenter(
|
||||
room: FakeJoinedRoom = FakeJoinedRoom(),
|
||||
endPollAction: EndPollAction = FakeEndPollAction(),
|
||||
sendPollResponseAction: SendPollResponseAction = FakeSendPollResponseAction(),
|
||||
pollHistoryItemFactory: PollHistoryItemsFactory = PollHistoryItemsFactory(
|
||||
pollContentStateFactory = DefaultPollContentStateFactory(FakeMatrixClient()),
|
||||
dateFormatter = FakeDateFormatter(),
|
||||
dispatchers = testCoroutineDispatchers(),
|
||||
),
|
||||
): PollHistoryPresenter {
|
||||
return PollHistoryPresenter(
|
||||
sessionCoroutineScope = this,
|
||||
sendPollResponseAction = sendPollResponseAction,
|
||||
endPollAction = endPollAction,
|
||||
pollHistoryItemFactory = pollHistoryItemFactory,
|
||||
room = room,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun TestScope.createPollHistoryPresenter(
|
||||
room: FakeJoinedRoom = FakeJoinedRoom(),
|
||||
endPollAction: EndPollAction = FakeEndPollAction(),
|
||||
sendPollResponseAction: SendPollResponseAction = FakeSendPollResponseAction(),
|
||||
pollHistoryItemFactory: PollHistoryItemsFactory = PollHistoryItemsFactory(
|
||||
pollContentStateFactory = DefaultPollContentStateFactory(FakeMatrixClient()),
|
||||
dateFormatter = FakeDateFormatter(),
|
||||
dispatchers = testCoroutineDispatchers(),
|
||||
),
|
||||
): PollHistoryPresenter {
|
||||
return PollHistoryPresenter(
|
||||
sessionCoroutineScope = this,
|
||||
sendPollResponseAction = sendPollResponseAction,
|
||||
endPollAction = endPollAction,
|
||||
pollHistoryItemFactory = pollHistoryItemFactory,
|
||||
room = room,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user