diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt index 1c797c023a66..05fc574f784c 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt @@ -86,7 +86,7 @@ class ConnectViewModel( tunnelState = tunnelState, showLocation = when (tunnelState) { - is TunnelState.Disconnected -> true + is TunnelState.Disconnected -> tunnelState.location != null is TunnelState.Disconnecting -> { when (tunnelState.actionAfterDisconnect) { ActionAfterDisconnect.Nothing -> false 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 0d61b3e300f8..1dab9a456535 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 @@ -171,12 +171,11 @@ class ConnectViewModelTest { fun `given RelayListUseCase returns new selectedRelayItem uiState should emit new selectedRelayItem`() = runTest { val selectedRelayItemTitle = "Item" - selectedRelayItemFlow.value = selectedRelayItemTitle - viewModel.uiState.test { assertEquals(ConnectUiState.INITIAL, awaitItem()) - val result = awaitItem() - assertEquals(selectedRelayItemTitle, result.selectedRelayItemTitle) + + selectedRelayItemFlow.value = selectedRelayItemTitle + assertEquals(selectedRelayItemTitle, awaitItem().selectedRelayItemTitle) } } @@ -196,7 +195,6 @@ class ConnectViewModelTest { // Act, Assert viewModel.uiState.test { - assertEquals(ConnectUiState.INITIAL, awaitItem()) tunnelState.emit(TunnelState.Disconnected(null)) // Start of with no location @@ -215,12 +213,7 @@ class ConnectViewModelTest { val locationTestItem = null // Act, Assert - viewModel.uiState.test { - assertEquals(ConnectUiState.INITIAL, awaitItem()) - expectNoEvents() - val result = awaitItem() - assertEquals(locationTestItem, result.location) - } + viewModel.uiState.test { assertEquals(locationTestItem, awaitItem().location) } } @Test @@ -278,15 +271,12 @@ class ConnectViewModelTest { val mockErrorState: ErrorState = mockk() val expectedConnectNotificationState = InAppNotification.TunnelStateError(mockErrorState) - val tunnelStateError = TunnelState.Error(mockErrorState) - notifications.value = listOf(expectedConnectNotificationState) // Act, Assert viewModel.uiState.test { assertEquals(ConnectUiState.INITIAL, awaitItem()) - tunnelState.emit(tunnelStateError) - val result = awaitItem() - assertEquals(expectedConnectNotificationState, result.inAppNotification) + notifications.value = listOf(expectedConnectNotificationState) + assertEquals(expectedConnectNotificationState, awaitItem().inAppNotification) } } @@ -315,7 +305,6 @@ class ConnectViewModelTest { viewModel.uiState.test { awaitItem() outOfTimeViewFlow.value = true - awaitItem() } // Assert @@ -328,12 +317,13 @@ class ConnectViewModelTest { // Arrange val tunnel = TunnelState.Error(mockk(relaxed = true)) val lastKnownLocation: GeoIpLocation = mockk(relaxed = true) - lastKnownLocationFlow.emit(lastKnownLocation) - tunnelState.emit(tunnel) // Act, Assert viewModel.uiState.test { assertEquals(ConnectUiState.INITIAL, awaitItem()) + lastKnownLocationFlow.emit(lastKnownLocation) + tunnelState.emit(tunnel) + awaitItem() val result = awaitItem() assertEquals(lastKnownLocation, result.location) }