Unit tests for view navigator

This commit is contained in:
Maxime NATUREL 2022-09-26 10:08:59 +02:00
parent 0c708c0ad4
commit bf42220422
2 changed files with 18 additions and 1 deletions

View File

@ -32,7 +32,6 @@ class SessionOverviewViewNavigator @Inject constructor() {
context.startActivity(RenameSessionActivity.newIntent(context, deviceId))
}
// TODO add unit test
fun goBack(fragmentActivity: FragmentActivity) {
fragmentActivity.finish()
}

View File

@ -17,12 +17,15 @@
package im.vector.app.features.settings.devices.v2.overview
import android.content.Intent
import androidx.fragment.app.FragmentActivity
import im.vector.app.features.settings.devices.v2.details.SessionDetailsActivity
import im.vector.app.features.settings.devices.v2.rename.RenameSessionActivity
import im.vector.app.test.fakes.FakeContext
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.runs
import io.mockk.unmockkAll
import io.mockk.verify
import org.junit.After
@ -77,6 +80,21 @@ class SessionOverviewViewNavigatorTest {
}
}
@Test
fun `given an activity when going back then the activity is finished`() {
// Given
val fragmentActivity = mockk<FragmentActivity>()
every { fragmentActivity.finish() } just runs
// When
sessionOverviewViewNavigator.goBack(fragmentActivity)
// Then
verify {
fragmentActivity.finish()
}
}
private fun givenIntentForSessionDetails(sessionId: String): Intent {
val intent = mockk<Intent>()
every { SessionDetailsActivity.newIntent(context.instance, sessionId) } returns intent