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 3b5da50d3374..7e66bc24d9fa 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 @@ -56,7 +56,10 @@ class SelectLocationScreenTest { uiState = SelectLocationUiState.ShowData( countries = DUMMY_RELAY_COUNTRIES, - selectedRelay = null + selectedRelay = null, + selectedOwnership = null, + selectedProvidersCount = 0, + searchTerm = "" ), uiCloseAction = MutableSharedFlow(), enterTransitionEndAction = MutableSharedFlow().asSharedFlow() @@ -93,7 +96,10 @@ class SelectLocationScreenTest { uiState = SelectLocationUiState.ShowData( countries = updatedDummyList, - selectedRelay = updatedDummyList[0].cities[0].relays[0] + selectedRelay = updatedDummyList[0].cities[0].relays[0], + selectedOwnership = null, + selectedProvidersCount = 0, + searchTerm = "" ), uiCloseAction = MutableSharedFlow(), enterTransitionEndAction = MutableSharedFlow().asSharedFlow() @@ -118,7 +124,13 @@ class SelectLocationScreenTest { composeTestRule.setContentWithTheme { SelectLocationScreen( uiState = - SelectLocationUiState.ShowData(countries = emptyList(), selectedRelay = null), + SelectLocationUiState.ShowData( + countries = emptyList(), + selectedRelay = null, + selectedOwnership = null, + selectedProvidersCount = 0, + searchTerm = "" + ), uiCloseAction = MutableSharedFlow(), enterTransitionEndAction = MutableSharedFlow().asSharedFlow(), onSearchTermInput = mockedSearchTermInput @@ -140,7 +152,14 @@ class SelectLocationScreenTest { val mockSearchString = "SEARCH" composeTestRule.setContentWithTheme { SelectLocationScreen( - uiState = SelectLocationUiState.NoSearchResultFound(searchTerm = mockSearchString), + uiState = + SelectLocationUiState.ShowData( + countries = emptyList(), + selectedRelay = null, + selectedOwnership = null, + selectedProvidersCount = 0, + searchTerm = mockSearchString + ), uiCloseAction = MutableSharedFlow(), enterTransitionEndAction = MutableSharedFlow().asSharedFlow(), onSearchTermInput = mockedSearchTermInput @@ -187,7 +206,7 @@ class SelectLocationScreenTest { private val DUMMY_RELAY_COUNTRIES = RelayList( arrayListOf(DUMMY_RELAY_COUNTRY_1, DUMMY_RELAY_COUNTRY_2), - DUMMY_WIREGUARD_ENDPOINT_DATA + DUMMY_WIREGUARD_ENDPOINT_DATA, ) .toRelayCountries(ownership = Constraint.Any(), providers = Constraint.Any()) } 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 44be67fa648f..74d7d80c1901 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 @@ -15,7 +15,11 @@ import kotlinx.coroutines.test.runTest import net.mullvad.mullvadvpn.compose.state.SelectLocationUiState import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule import net.mullvad.mullvadvpn.lib.common.test.assertLists +import net.mullvad.mullvadvpn.model.Constraint import net.mullvad.mullvadvpn.model.GeographicLocationConstraint +import net.mullvad.mullvadvpn.model.Ownership +import net.mullvad.mullvadvpn.model.Providers +import net.mullvad.mullvadvpn.relaylist.Provider import net.mullvad.mullvadvpn.relaylist.RelayCountry import net.mullvad.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.relaylist.RelayList @@ -23,6 +27,7 @@ import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm import net.mullvad.mullvadvpn.ui.serviceconnection.ConnectionProxy import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager import net.mullvad.mullvadvpn.ui.serviceconnection.connectionProxy +import net.mullvad.mullvadvpn.usecase.RelayListFilterUseCase import net.mullvad.mullvadvpn.usecase.RelayListUseCase import org.junit.After import org.junit.Before @@ -32,21 +37,31 @@ import org.junit.Test class SelectLocationViewModelTest { @get:Rule val testCoroutineRule = TestCoroutineRule() + private val mockRelayListFilterUseCase: RelayListFilterUseCase = mockk(relaxed = true) private val mockServiceConnectionManager: ServiceConnectionManager = mockk() private lateinit var viewModel: SelectLocationViewModel - private val relayListWithSelectionFlow = MutableStateFlow(RelayList(emptyList(), null)) - private val mockRelayListUseCase: RelayListUseCase = mockk() + private val selectedOwnership = MutableStateFlow>(Constraint.Any()) + private val selectedProvider = MutableStateFlow>(Constraint.Any()) + private val allProvider = MutableStateFlow>(emptyList()) @Before fun setup() { + + every { mockRelayListFilterUseCase.selectedOwnership() } returns selectedOwnership + every { mockRelayListFilterUseCase.selectedProviders() } returns selectedProvider + every { mockRelayListFilterUseCase.availableProviders() } returns allProvider every { mockRelayListUseCase.relayListWithSelection() } returns relayListWithSelectionFlow mockkStatic(SERVICE_CONNECTION_MANAGER_EXTENSIONS) mockkStatic(RELAY_LIST_EXTENSIONS) - - viewModel = SelectLocationViewModel(mockServiceConnectionManager, mockRelayListUseCase) + viewModel = + SelectLocationViewModel( + mockServiceConnectionManager, + mockRelayListUseCase, + mockRelayListFilterUseCase + ) } @After @@ -164,11 +179,47 @@ class SelectLocationViewModelTest { // Assert val actualState = awaitItem() - assertIs(actualState) + assertIs(actualState) assertEquals(mockSearchString, actualState.searchTerm) } } + @Test + fun testRemoveOwnerFilter() = runTest { + // Arrange + val mockSelectedProviders: Constraint = mockk() + every { mockRelayListFilterUseCase.selectedProviders() } returns + MutableStateFlow(mockSelectedProviders) + + // Act + viewModel.removeOwnerFilter() + // Assert + verify { + mockRelayListFilterUseCase.updateOwnershipAndProviderFilter( + any>(), + mockSelectedProviders + ) + } + } + + @Test + fun testRemoveProviderFilter() = runTest { + // Arrange + val mockSelectedOwnership: Constraint = mockk() + every { mockRelayListFilterUseCase.selectedOwnership() } returns + MutableStateFlow(mockSelectedOwnership) + + // Act + viewModel.removeProviderFilter() + // Assert + verify { + mockRelayListFilterUseCase.updateOwnershipAndProviderFilter( + mockSelectedOwnership, + any>() + ) + } + } + companion object { private const val SERVICE_CONNECTION_MANAGER_EXTENSIONS = "net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManagerExtensionsKt"