Unit tests for navigator
This commit is contained in:
parent
ebf707dca9
commit
26dbd31717
@ -20,7 +20,6 @@ import android.content.Context
|
|||||||
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity
|
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
// TODO add unit tests
|
|
||||||
class VectorSettingsDevicesViewNavigator @Inject constructor() {
|
class VectorSettingsDevicesViewNavigator @Inject constructor() {
|
||||||
|
|
||||||
fun navigateToSessionOverview(context: Context, sessionId: String) {
|
fun navigateToSessionOverview(context: Context, sessionId: String) {
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 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.settings.devices.v2
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity
|
||||||
|
import im.vector.app.test.fakes.FakeContext
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.mockkObject
|
||||||
|
import io.mockk.unmockkAll
|
||||||
|
import io.mockk.verify
|
||||||
|
import org.junit.After
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
private const val A_SESSION_ID = "session_id"
|
||||||
|
|
||||||
|
class VectorSettingsDevicesViewNavigatorTest {
|
||||||
|
|
||||||
|
private val context = FakeContext()
|
||||||
|
private val vectorSettingsDevicesViewNavigator = VectorSettingsDevicesViewNavigator()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
mockkObject(SessionOverviewActivity.Companion)
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
fun tearDown() {
|
||||||
|
unmockkAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given a session id when navigating to overview then it starts the correct activity`() {
|
||||||
|
val intent = givenIntentForSessionOverview(A_SESSION_ID)
|
||||||
|
context.givenStartActivity(intent)
|
||||||
|
|
||||||
|
vectorSettingsDevicesViewNavigator.navigateToSessionOverview(context.instance, A_SESSION_ID)
|
||||||
|
|
||||||
|
verify {
|
||||||
|
context.instance.startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun givenIntentForSessionOverview(sessionId: String): Intent {
|
||||||
|
val intent = mockk<Intent>()
|
||||||
|
every { SessionOverviewActivity.newIntent(context.instance, sessionId) } returns intent
|
||||||
|
return intent
|
||||||
|
}
|
||||||
|
}
|
@ -18,11 +18,14 @@ package im.vector.app.test.fakes
|
|||||||
|
|
||||||
import android.content.ContentResolver
|
import android.content.ContentResolver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
import android.net.ConnectivityManager
|
import android.net.ConnectivityManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
|
import io.mockk.just
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
|
import io.mockk.runs
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
||||||
class FakeContext(
|
class FakeContext(
|
||||||
@ -67,4 +70,8 @@ class FakeContext(
|
|||||||
connectivityManager.givenHasActiveConnection()
|
connectivityManager.givenHasActiveConnection()
|
||||||
givenService(Context.CONNECTIVITY_SERVICE, ConnectivityManager::class.java, connectivityManager.instance)
|
givenService(Context.CONNECTIVITY_SERVICE, ConnectivityManager::class.java, connectivityManager.instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenStartActivity(intent: Intent) {
|
||||||
|
every { instance.startActivity(intent) } just runs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user