diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt index fbc8b046fd77..bb64adc8a68f 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt @@ -9,6 +9,7 @@ import io.mockk.MockKAnnotations import io.mockk.mockk import io.mockk.verify import net.mullvad.mullvadvpn.compose.setContentWithTheme +import net.mullvad.mullvadvpn.compose.state.RelayListState import net.mullvad.mullvadvpn.compose.state.SelectLocationUiState import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR import net.mullvad.mullvadvpn.model.Constraint @@ -54,9 +55,12 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( uiState = - SelectLocationUiState.ShowData( - countries = DUMMY_RELAY_COUNTRIES, - selectedRelay = null, + SelectLocationUiState.Data( + relayListState = + RelayListState.RelayList( + countries = DUMMY_RELAY_COUNTRIES, + selectedRelay = null + ), selectedOwnership = null, selectedProvidersCount = 0, searchTerm = "" @@ -91,9 +95,12 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( uiState = - SelectLocationUiState.ShowData( - countries = updatedDummyList, - selectedRelay = updatedDummyList[0].cities[0].relays[0], + SelectLocationUiState.Data( + relayListState = + RelayListState.RelayList( + countries = updatedDummyList, + selectedRelay = updatedDummyList[0].cities[0].relays[0] + ), selectedOwnership = null, selectedProvidersCount = 0, searchTerm = "" @@ -118,9 +125,12 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( uiState = - SelectLocationUiState.ShowData( - countries = emptyList(), - selectedRelay = null, + SelectLocationUiState.Data( + relayListState = + RelayListState.RelayList( + countries = emptyList(), + selectedRelay = null + ), selectedOwnership = null, selectedProvidersCount = 0, searchTerm = "" @@ -146,9 +156,8 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( uiState = - SelectLocationUiState.ShowData( - countries = emptyList(), - selectedRelay = null, + SelectLocationUiState.Data( + relayListState = RelayListState.Empty, selectedOwnership = null, selectedProvidersCount = 0, searchTerm = mockSearchString diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt index 46ea0bf3fb68..fc6408d8ab7e 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt @@ -3,8 +3,10 @@ package net.mullvad.mullvadvpn.viewmodel import androidx.lifecycle.viewModelScope import app.cash.turbine.test import io.mockk.every +import io.mockk.just import io.mockk.mockk import io.mockk.mockkStatic +import io.mockk.runs import io.mockk.unmockkAll import io.mockk.verify import kotlin.test.assertEquals @@ -12,6 +14,7 @@ import kotlin.test.assertIs import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.runTest +import net.mullvad.mullvadvpn.compose.state.RelayListState import net.mullvad.mullvadvpn.compose.state.SelectLocationUiState import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule import net.mullvad.mullvadvpn.lib.common.test.assertLists @@ -53,6 +56,7 @@ class SelectLocationViewModelTest { every { mockRelayListFilterUseCase.selectedProviders() } returns selectedProvider every { mockRelayListFilterUseCase.availableProviders() } returns allProvider every { mockRelayListUseCase.relayListWithSelection() } returns relayListWithSelectionFlow + every { mockRelayListUseCase.fetchRelayList() } just runs mockkStatic(SERVICE_CONNECTION_MANAGER_EXTENSIONS) mockkStatic(RELAY_LIST_EXTENSIONS) @@ -86,9 +90,16 @@ class SelectLocationViewModelTest { // Act, Assert viewModel.uiState.test { val actualState = awaitItem() - assertIs(actualState) - assertLists(mockCountries, actualState.countries) - assertEquals(selectedRelay, actualState.selectedRelay) + assertIs(actualState) + assertIs(actualState.relayListState) + assertLists( + mockCountries, + (actualState.relayListState as RelayListState.RelayList).countries + ) + assertEquals( + selectedRelay, + (actualState.relayListState as RelayListState.RelayList).selectedRelay + ) } } @@ -103,9 +114,16 @@ class SelectLocationViewModelTest { // Act, Assert viewModel.uiState.test { val actualState = awaitItem() - assertIs(actualState) - assertLists(mockCountries, actualState.countries) - assertEquals(selectedRelay, actualState.selectedRelay) + assertIs(actualState) + assertIs(actualState.relayListState) + assertLists( + mockCountries, + (actualState.relayListState as RelayListState.RelayList).countries + ) + assertEquals( + selectedRelay, + (actualState.relayListState as RelayListState.RelayList).selectedRelay + ) } } @@ -145,16 +163,23 @@ class SelectLocationViewModelTest { // Act, Assert viewModel.uiState.test { // Wait for first data - assertIs(awaitItem()) + assertIs(awaitItem()) // Update search string viewModel.onSearchTermInput(mockSearchString) // Assert val actualState = awaitItem() - assertIs(actualState) - assertLists(mockCountries, actualState.countries) - assertEquals(selectedRelay, actualState.selectedRelay) + assertIs(actualState) + assertIs(actualState.relayListState) + assertLists( + mockCountries, + (actualState.relayListState as RelayListState.RelayList).countries + ) + assertEquals( + selectedRelay, + (actualState.relayListState as RelayListState.RelayList).selectedRelay + ) } } @@ -172,14 +197,14 @@ class SelectLocationViewModelTest { // Act, Assert viewModel.uiState.test { // Wait for first data - assertIs(awaitItem()) + assertIs(awaitItem()) // Update search string viewModel.onSearchTermInput(mockSearchString) // Assert val actualState = awaitItem() - assertIs(actualState) + assertIs(actualState) assertEquals(mockSearchString, actualState.searchTerm) } }