summaryrefslogtreecommitdiffhomepage
path: root/android/app/src/test
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2023-10-13 11:04:45 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2023-10-13 11:04:45 +0200
commit6842d204e3585b216f7e271ecb9eaf4a158ee666 (patch)
treed5bac59e0f8a4daf7b5db9c4d51ee9714aa54405 /android/app/src/test
parentbd2bdbedd280ca84a543472143c959d655651a73 (diff)
parente72415c31be76c019ec135ccb231560454675e7e (diff)
downloadmullvadvpn-6842d204e3585b216f7e271ecb9eaf4a158ee666.tar.xz
mullvadvpn-6842d204e3585b216f7e271ecb9eaf4a158ee666.zip
Merge branch 'add-device-name-and-time-left-to-main-view-droid-90'
Diffstat (limited to 'android/app/src/test')
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt11
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModelTest.kt9
2 files changed, 19 insertions, 1 deletions
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt
index 18f8447f44..bddaee353e 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModelTest.kt
@@ -20,11 +20,13 @@ import net.mullvad.mullvadvpn.compose.state.ConnectNotificationState
import net.mullvad.mullvadvpn.compose.state.ConnectUiState
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
import net.mullvad.mullvadvpn.model.AccountExpiry
+import net.mullvad.mullvadvpn.model.DeviceState
import net.mullvad.mullvadvpn.model.GeoIpLocation
import net.mullvad.mullvadvpn.model.TunnelState
import net.mullvad.mullvadvpn.relaylist.RelayCountry
import net.mullvad.mullvadvpn.relaylist.RelayItem
import net.mullvad.mullvadvpn.repository.AccountRepository
+import net.mullvad.mullvadvpn.repository.DeviceRepository
import net.mullvad.mullvadvpn.ui.VersionInfo
import net.mullvad.mullvadvpn.ui.serviceconnection.AppVersionInfoCache
import net.mullvad.mullvadvpn.ui.serviceconnection.AuthTokenCache
@@ -65,6 +67,7 @@ class ConnectViewModelTest {
)
)
private val accountExpiryState = MutableStateFlow<AccountExpiry>(AccountExpiry.Missing)
+ private val deviceState = MutableStateFlow<DeviceState>(DeviceState.Initial)
// Service connections
private val mockServiceConnectionContainer: ServiceConnectionContainer = mockk()
@@ -77,6 +80,9 @@ class ConnectViewModelTest {
// Account Repository
private val mockAccountRepository: AccountRepository = mockk()
+ // Device Repository
+ private val mockDeviceRepository: DeviceRepository = mockk()
+
// Captures
private val locationSlot = slot<((GeoIpLocation?) -> Unit)>()
private val relaySlot = slot<(List<RelayCountry>, RelayItem?) -> Unit>()
@@ -103,6 +109,8 @@ class ConnectViewModelTest {
every { mockAccountRepository.accountExpiryState } returns accountExpiryState
+ every { mockDeviceRepository.deviceState } returns deviceState
+
every { mockConnectionProxy.onUiStateChange } returns eventNotifierTunnelUiState
every { mockConnectionProxy.onStateChange } returns eventNotifierTunnelRealState
@@ -117,6 +125,7 @@ class ConnectViewModelTest {
ConnectViewModel(
serviceConnectionManager = mockServiceConnectionManager,
accountRepository = mockAccountRepository,
+ deviceRepository = mockDeviceRepository,
isVersionInfoNotificationEnabled = true
)
}
@@ -351,6 +360,7 @@ class ConnectViewModelTest {
val expectedConnectNotificationState =
ConnectNotificationState.ShowAccountExpiryNotification(mockDateTime)
every { mockDateTime.isBefore(any<ReadableInstant>()) } returns true
+ every { mockDateTime.toInstant().millis } returns 0
// Act, Assert
viewModel.uiState.test {
@@ -360,6 +370,7 @@ class ConnectViewModelTest {
locationSlot.captured.invoke(mockLocation)
relaySlot.captured.invoke(mockk(), mockk())
accountExpiryState.value = AccountExpiry.Available(mockDateTime)
+
val result = awaitItem()
assertEquals(expectedConnectNotificationState, result.connectNotificationState)
}
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModelTest.kt
index 5f81032938..8c1ec10f5a 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModelTest.kt
@@ -16,8 +16,10 @@ import kotlinx.coroutines.test.runTest
import net.mullvad.mullvadvpn.compose.state.OutOfTimeUiState
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
import net.mullvad.mullvadvpn.model.AccountExpiry
+import net.mullvad.mullvadvpn.model.DeviceState
import net.mullvad.mullvadvpn.model.TunnelState
import net.mullvad.mullvadvpn.repository.AccountRepository
+import net.mullvad.mullvadvpn.repository.DeviceRepository
import net.mullvad.mullvadvpn.ui.serviceconnection.AuthTokenCache
import net.mullvad.mullvadvpn.ui.serviceconnection.ConnectionProxy
import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionContainer
@@ -39,6 +41,7 @@ class OutOfTimeViewModelTest {
private val serviceConnectionState =
MutableStateFlow<ServiceConnectionState>(ServiceConnectionState.Disconnected)
private val accountExpiryState = MutableStateFlow<AccountExpiry>(AccountExpiry.Missing)
+ private val deviceState = MutableStateFlow<DeviceState>(DeviceState.Initial)
// Service connections
private val mockServiceConnectionContainer: ServiceConnectionContainer = mockk()
@@ -48,6 +51,7 @@ class OutOfTimeViewModelTest {
private val eventNotifierTunnelRealState = EventNotifier<TunnelState>(TunnelState.Disconnected)
private val mockAccountRepository: AccountRepository = mockk()
+ private val mockDeviceRepository: DeviceRepository = mockk()
private val mockServiceConnectionManager: ServiceConnectionManager = mockk()
private lateinit var viewModel: OutOfTimeViewModel
@@ -64,10 +68,13 @@ class OutOfTimeViewModelTest {
every { mockAccountRepository.accountExpiryState } returns accountExpiryState
+ every { mockDeviceRepository.deviceState } returns deviceState
+
viewModel =
OutOfTimeViewModel(
accountRepository = mockAccountRepository,
serviceConnectionManager = mockServiceConnectionManager,
+ deviceRepository = mockDeviceRepository,
pollAccountExpiry = false
)
}
@@ -104,7 +111,7 @@ class OutOfTimeViewModelTest {
// Act, Assert
viewModel.uiState.test {
- assertEquals(OutOfTimeUiState(), awaitItem())
+ assertEquals(OutOfTimeUiState(deviceName = ""), awaitItem())
serviceConnectionState.value =
ServiceConnectionState.ConnectedReady(mockServiceConnectionContainer)
eventNotifierTunnelRealState.notify(tunnelRealStateTestItem)