diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailNavigator.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailNavigator.kt index 402b9c4468..a19bb87d9e 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailNavigator.kt @@ -20,7 +20,6 @@ import android.content.Context import im.vector.app.features.navigation.Navigator import javax.inject.Inject -// TODO add unit tests class RoomPollDetailNavigator @Inject constructor( private val navigator: Navigator, ) { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListNavigator.kt b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListNavigator.kt index c377d21490..9085f95ca1 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListNavigator.kt @@ -20,7 +20,6 @@ import android.content.Context import im.vector.app.features.roomprofile.polls.detail.ui.RoomPollDetailActivity import javax.inject.Inject -// TODO add unit tests class RoomPollsListNavigator @Inject constructor() { fun goToPollDetails(context: Context, pollId: String, roomId: String, isEnded: Boolean) { diff --git a/vector/src/test/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailNavigatorTest.kt b/vector/src/test/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailNavigatorTest.kt new file mode 100644 index 0000000000..9c5a3cc320 --- /dev/null +++ b/vector/src/test/java/im/vector/app/features/roomprofile/polls/detail/ui/RoomPollDetailNavigatorTest.kt @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.roomprofile.polls.detail.ui + +import android.content.Context +import im.vector.app.test.fakes.FakeNavigator +import io.mockk.mockk +import org.junit.Test + +internal class RoomPollDetailNavigatorTest { + + private val fakeNavigator = FakeNavigator() + + private val roomPollDetailNavigator = RoomPollDetailNavigator( + navigator = fakeNavigator.instance, + ) + + @Test + fun `given main navigator when goToTimelineEvent then correct method main navigator is called`() { + // Given + val aContext = mockk() + val aRoomId = "roomId" + val anEventId = "eventId" + fakeNavigator.givenOpenRoomSuccess( + context = aContext, + roomId = aRoomId, + eventId = anEventId, + buildTask = true, + isInviteAlreadyAccepted = false, + trigger = null, + ) + + // When + roomPollDetailNavigator.goToTimelineEvent(aContext, aRoomId, anEventId) + + // Then + fakeNavigator.verifyOpenRoom( + context = aContext, + roomId = aRoomId, + eventId = anEventId, + buildTask = true, + isInviteAlreadyAccepted = false, + trigger = null, + ) + } +} diff --git a/vector/src/test/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListNavigatorTest.kt b/vector/src/test/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListNavigatorTest.kt new file mode 100644 index 0000000000..c2d1198081 --- /dev/null +++ b/vector/src/test/java/im/vector/app/features/roomprofile/polls/list/ui/RoomPollsListNavigatorTest.kt @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.roomprofile.polls.list.ui + +import android.content.Intent +import im.vector.app.features.roomprofile.polls.detail.ui.RoomPollDetailActivity +import im.vector.app.test.fakes.FakeContext +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject +import io.mockk.unmockkAll +import org.junit.After +import org.junit.Before +import org.junit.Test + +internal class RoomPollsListNavigatorTest { + + private val fakeContext = FakeContext() + private val roomPollsListNavigator = RoomPollsListNavigator() + + @Before + fun setUp() { + mockkObject(RoomPollDetailActivity.Companion) + } + + @After + fun tearDown() { + unmockkAll() + } + + @Test + fun `given info about poll when goToPollDetails then it starts the correct activity`() { + // Given + val aPollId = "pollId" + val aRoomId = "roomId" + val isEnded = true + val intent = givenIntentForPollDetails(aPollId, aRoomId, isEnded) + fakeContext.givenStartActivity(intent) + + // When + roomPollsListNavigator.goToPollDetails(fakeContext.instance, aPollId, aRoomId, isEnded) + + // Then + fakeContext.verifyStartActivity(intent) + } + + private fun givenIntentForPollDetails(pollId: String, roomId: String, isEnded: Boolean): Intent { + val intent = mockk() + every { RoomPollDetailActivity.newIntent(fakeContext.instance, pollId, roomId, isEnded) } returns intent + return intent + } +} diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeNavigator.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeNavigator.kt new file mode 100644 index 0000000000..36d3305ec6 --- /dev/null +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeNavigator.kt @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.test.fakes + +import android.content.Context +import im.vector.app.features.analytics.plan.ViewRoom +import im.vector.app.features.navigation.Navigator +import io.mockk.justRun +import io.mockk.mockk +import io.mockk.verify + +class FakeNavigator { + + val instance: Navigator = mockk() + + fun givenOpenRoomSuccess( + context: Context, + roomId: String, + eventId: String?, + buildTask: Boolean, + isInviteAlreadyAccepted: Boolean, + trigger: ViewRoom.Trigger?, + ) { + justRun { instance.openRoom(context, roomId, eventId, buildTask, isInviteAlreadyAccepted, trigger) } + } + + fun verifyOpenRoom( + context: Context, + roomId: String, + eventId: String?, + buildTask: Boolean, + isInviteAlreadyAccepted: Boolean, + trigger: ViewRoom.Trigger?, + ) { + verify { instance.openRoom(context, roomId, eventId, buildTask, isInviteAlreadyAccepted, trigger) } + } +}