mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Unit tests for navigator
This commit is contained in:
parent
ba1549048d
commit
a1102738d0
3 changed files with 72 additions and 1 deletions
|
@ -20,7 +20,6 @@ import android.content.Context
|
|||
import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
// TODO add unit tests
|
||||
class VectorSettingsDevicesViewNavigator @Inject constructor() {
|
||||
|
||||
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.Context
|
||||
import android.content.Intent
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.ParcelFileDescriptor
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.runs
|
||||
import java.io.OutputStream
|
||||
|
||||
class FakeContext(
|
||||
|
@ -67,4 +70,8 @@ class FakeContext(
|
|||
connectivityManager.givenHasActiveConnection()
|
||||
givenService(Context.CONNECTIVITY_SERVICE, ConnectivityManager::class.java, connectivityManager.instance)
|
||||
}
|
||||
|
||||
fun givenStartActivity(intent: Intent) {
|
||||
every { instance.startActivity(intent) } just runs
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue