summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson90@gmail.com>2023-10-10 15:56:48 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2023-10-13 11:03:58 +0200
commite72415c31be76c019ec135ccb231560454675e7e (patch)
treed5bac59e0f8a4daf7b5db9c4d51ee9714aa54405 /android
parentc07ad9f01246937018ad4ae8021afa208641bfa1 (diff)
downloadmullvadvpn-e72415c31be76c019ec135ccb231560454675e7e.tar.xz
mullvadvpn-e72415c31be76c019ec135ccb231560454675e7e.zip
Fix tests
Diffstat (limited to 'android')
-rw-r--r--android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt44
-rw-r--r--android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt16
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt1
-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
6 files changed, 75 insertions, 10 deletions
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt
index 02a148b22d..68cfa2b92c 100644
--- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt
+++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt
@@ -83,6 +83,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowTunnelStateNotificationBlocked
),
@@ -118,6 +120,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowTunnelStateNotificationBlocked
),
@@ -151,6 +155,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow()
@@ -182,6 +188,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow()
@@ -214,6 +222,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow()
@@ -246,6 +256,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow()
@@ -280,6 +292,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowTunnelStateNotificationError(
ErrorState(ErrorStateCause.StartTunnelError, true)
@@ -318,6 +332,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowTunnelStateNotificationError(
ErrorState(ErrorStateCause.StartTunnelError, false)
@@ -353,6 +369,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowTunnelStateNotificationBlocked
),
@@ -388,6 +406,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = true,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowTunnelStateNotificationBlocked
),
@@ -423,6 +443,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow(),
@@ -454,6 +476,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow(),
@@ -485,6 +509,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow(),
@@ -515,6 +541,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow(),
@@ -545,6 +573,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow(),
@@ -576,6 +606,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow(),
@@ -614,6 +646,8 @@ class ConnectScreenTest {
outAddress = mockOutAddress,
showLocation = false,
isTunnelInfoExpanded = true,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState = ConnectNotificationState.HideNotification
),
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow()
@@ -651,6 +685,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowVersionInfoNotification(versionInfo)
),
@@ -687,6 +723,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowVersionInfoNotification(versionInfo)
),
@@ -720,6 +758,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = null,
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowAccountExpiryNotification(expiryDate)
),
@@ -758,6 +798,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowVersionInfoNotification(versionInfo)
),
@@ -790,6 +832,8 @@ class ConnectScreenTest {
outAddress = "",
showLocation = false,
isTunnelInfoExpanded = false,
+ deviceName = "",
+ daysLeftUntilExpiry = null,
connectNotificationState =
ConnectNotificationState.ShowAccountExpiryNotification(expiryDate)
),
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt
index a177aa8ac1..95b44f8286 100644
--- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt
+++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt
@@ -29,7 +29,7 @@ class OutOfTimeScreenTest {
composeTestRule.setContent {
OutOfTimeScreen(
showSitePayment = false,
- uiState = OutOfTimeUiState(),
+ uiState = OutOfTimeUiState(deviceName = ""),
uiSideEffect = MutableSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
@@ -57,7 +57,7 @@ class OutOfTimeScreenTest {
composeTestRule.setContent {
OutOfTimeScreen(
showSitePayment = true,
- uiState = OutOfTimeUiState(),
+ uiState = OutOfTimeUiState(deviceName = ""),
uiSideEffect =
MutableStateFlow(OutOfTimeViewModel.UiSideEffect.OpenAccountView("222")),
onSitePaymentClick = {},
@@ -80,7 +80,7 @@ class OutOfTimeScreenTest {
composeTestRule.setContent {
OutOfTimeScreen(
showSitePayment = true,
- uiState = OutOfTimeUiState(),
+ uiState = OutOfTimeUiState(deviceName = ""),
uiSideEffect = MutableStateFlow(OutOfTimeViewModel.UiSideEffect.OpenConnectScreen),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
@@ -102,7 +102,7 @@ class OutOfTimeScreenTest {
composeTestRule.setContent {
OutOfTimeScreen(
showSitePayment = true,
- uiState = OutOfTimeUiState(),
+ uiState = OutOfTimeUiState(deviceName = ""),
uiSideEffect = MutableSharedFlow(),
onSitePaymentClick = mockClickListener,
onRedeemVoucherClick = {},
@@ -127,7 +127,7 @@ class OutOfTimeScreenTest {
composeTestRule.setContent {
OutOfTimeScreen(
showSitePayment = true,
- uiState = OutOfTimeUiState(),
+ uiState = OutOfTimeUiState(deviceName = ""),
uiSideEffect = MutableSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = mockClickListener,
@@ -152,7 +152,11 @@ class OutOfTimeScreenTest {
composeTestRule.setContent {
OutOfTimeScreen(
showSitePayment = true,
- uiState = OutOfTimeUiState(tunnelState = TunnelState.Connecting(null, null)),
+ uiState =
+ OutOfTimeUiState(
+ tunnelState = TunnelState.Connecting(null, null),
+ deviceName = ""
+ ),
uiSideEffect = MutableSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt
index 93e1e291a2..5e8fc2c78b 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/TopBar.kt
@@ -221,7 +221,7 @@ fun MullvadMediumTopBar(
@Preview
@Composable
-fun PreviewMullvadTopBarWithLongDeviceName() {
+private fun PreviewMullvadTopBarWithLongDeviceName() {
AppTheme {
Surface {
MullvadTopBarWithDeviceName(
@@ -238,7 +238,7 @@ fun PreviewMullvadTopBarWithLongDeviceName() {
@Preview
@Composable
-fun PreviewMullvadTopBarWithShortDeviceName() {
+private fun PreviewMullvadTopBarWithShortDeviceName() {
AppTheme {
Surface {
MullvadTopBarWithDeviceName(
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt
index 9374f4ab9a..f694079ae3 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreen.kt
@@ -36,7 +36,6 @@ import net.mullvad.mullvadvpn.compose.component.ConnectionStatusText
import net.mullvad.mullvadvpn.compose.component.LocationInfo
import net.mullvad.mullvadvpn.compose.component.Notification
import net.mullvad.mullvadvpn.compose.component.ScaffoldWithTopBarAndDeviceName
-import net.mullvad.mullvadvpn.compose.component.ScaffoldWithTopBar
import net.mullvad.mullvadvpn.compose.component.drawVerticalScrollbar
import net.mullvad.mullvadvpn.compose.state.ConnectUiState
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
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)