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 02a148b22d85..68cfa2b92c06 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().asSharedFlow() @@ -182,6 +188,8 @@ class ConnectScreenTest { outAddress = "", showLocation = false, isTunnelInfoExpanded = false, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().asSharedFlow() @@ -214,6 +222,8 @@ class ConnectScreenTest { outAddress = "", showLocation = true, isTunnelInfoExpanded = false, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().asSharedFlow() @@ -246,6 +256,8 @@ class ConnectScreenTest { outAddress = "", showLocation = true, isTunnelInfoExpanded = false, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().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().asSharedFlow(), @@ -454,6 +476,8 @@ class ConnectScreenTest { outAddress = "", showLocation = false, isTunnelInfoExpanded = false, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().asSharedFlow(), @@ -485,6 +509,8 @@ class ConnectScreenTest { outAddress = "", showLocation = false, isTunnelInfoExpanded = false, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().asSharedFlow(), @@ -515,6 +541,8 @@ class ConnectScreenTest { outAddress = "", showLocation = false, isTunnelInfoExpanded = false, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().asSharedFlow(), @@ -545,6 +573,8 @@ class ConnectScreenTest { outAddress = "", showLocation = false, isTunnelInfoExpanded = false, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().asSharedFlow(), @@ -576,6 +606,8 @@ class ConnectScreenTest { outAddress = "", showLocation = false, isTunnelInfoExpanded = false, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().asSharedFlow(), @@ -614,6 +646,8 @@ class ConnectScreenTest { outAddress = mockOutAddress, showLocation = false, isTunnelInfoExpanded = true, + deviceName = "", + daysLeftUntilExpiry = null, connectNotificationState = ConnectNotificationState.HideNotification ), uiSideEffect = MutableSharedFlow().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 a177aa8ac199..95b44f82864a 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 c430e12ec1e3..93669fb829dc 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 @@ -220,7 +220,7 @@ fun MullvadMediumTopBar( @Preview @Composable -fun PreviewMullvadTopBarWithLongDeviceName() { +private fun PreviewMullvadTopBarWithLongDeviceName() { AppTheme { Surface { MullvadTopBarWithDeviceName( @@ -237,7 +237,7 @@ fun PreviewMullvadTopBarWithLongDeviceName() { @Preview @Composable -fun PreviewMullvadTopBarWithShortDeviceName() { +private fun PreviewMullvadTopBarWithShortDeviceName() { AppTheme { Surface { MullvadTopBarWithDeviceName( 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 18f8447f4434..bddaee353ea9 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.Missing) + private val deviceState = MutableStateFlow(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, 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()) } 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 5f81032938f0..8c1ec10f5a22 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.Disconnected) private val accountExpiryState = MutableStateFlow(AccountExpiry.Missing) + private val deviceState = MutableStateFlow(DeviceState.Initial) // Service connections private val mockServiceConnectionContainer: ServiceConnectionContainer = mockk() @@ -48,6 +51,7 @@ class OutOfTimeViewModelTest { private val eventNotifierTunnelRealState = EventNotifier(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)