From 323e10171bcf3299a0161013bda0dba45c0878b2 Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Tue, 16 Apr 2024 14:12:46 +0200 Subject: [PATCH 1/3] Do not filter locations for custom lists With the exception of the select location screen list --- .../compose/screen/EditCustomListScreen.kt | 5 +- .../mullvadvpn/compose/util/PreviewData.kt | 5 +- .../mullvad/mullvadvpn/relaylist/RelayItem.kt | 3 ++ .../mullvad/mullvadvpn/relaylist/RelayList.kt | 3 +- .../relaylist/RelayListExtensions.kt | 48 ++++++++++++------- .../mullvadvpn/usecase/RelayListUseCase.kt | 18 +++++-- .../customlists/CustomListActionUseCase.kt | 4 +- .../viewmodel/CustomListLocationsViewModel.kt | 2 +- .../viewmodel/SelectLocationViewModel.kt | 13 ++++- 9 files changed, 71 insertions(+), 30 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/EditCustomListScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/EditCustomListScreen.kt index 87ed88d2639b..9186e639c56e 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/EditCustomListScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/EditCustomListScreen.kt @@ -45,6 +45,7 @@ import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition import net.mullvad.mullvadvpn.lib.theme.AppTheme import net.mullvad.mullvadvpn.lib.theme.Dimens import net.mullvad.mullvadvpn.model.GeographicLocationConstraint +import net.mullvad.mullvadvpn.model.Ownership import net.mullvad.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.viewmodel.EditCustomListViewModel import org.koin.androidx.compose.koinViewModel @@ -69,7 +70,9 @@ private fun PreviewEditCustomListScreen() { "hostname", "hostname", "hostname" - ) + ), + "Provider", + Ownership.MullvadOwned ) ) ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/PreviewData.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/PreviewData.kt index 61b563564ce4..3581d1d0b41d 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/PreviewData.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/util/PreviewData.kt @@ -1,6 +1,7 @@ package net.mullvad.mullvadvpn.compose.util import net.mullvad.mullvadvpn.model.GeographicLocationConstraint +import net.mullvad.mullvadvpn.model.Ownership import net.mullvad.mullvadvpn.relaylist.RelayItem fun generateRelayItemCountry( @@ -65,7 +66,9 @@ fun generateRelayItemRelay( hostname = hostName, ), locationName = "$cityCode $hostName", - active = active + active = active, + providerName = "Provider", + ownership = Ownership.MullvadOwned, ) private fun String.generateCountryCode() = (take(1) + takeLast(1)).lowercase() diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt index ce4be395b651..af4a0084d293 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.relaylist import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.GeoIpLocation import net.mullvad.mullvadvpn.model.GeographicLocationConstraint +import net.mullvad.mullvadvpn.model.Ownership sealed interface RelayItem { val name: String @@ -66,6 +67,8 @@ sealed interface RelayItem { override val locationName: String, override val active: Boolean, val location: GeographicLocationConstraint.Hostname, + val providerName: String, + val ownership: Ownership, ) : RelayItem { override val code = name override val hasChildren = false diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayList.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayList.kt index 30e4146245ac..e469aec11816 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayList.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayList.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.relaylist data class RelayList( val customLists: List, - val country: List, + val allCountries: List, + val filteredCountries: List, val selectedItem: RelayItem?, ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt index 882a3e42a4de..8d2ea5f34850 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt @@ -12,10 +12,7 @@ import net.mullvad.mullvadvpn.model.RelayList * filtered out and also relays that do not fit the ownership and provider list So are also cities * that only contains non-wireguard relays Countries, cities and relays are ordered by name */ -fun RelayList.toRelayCountries( - ownership: Constraint, - providers: Constraint -): List { +fun RelayList.toRelayCountries(): List { val relayCountries = this.countries .map { country -> @@ -33,8 +30,7 @@ fun RelayList.toRelayCountries( relays = relays ) - val validCityRelays = - city.relays.filterValidRelays(ownership = ownership, providers = providers) + val validCityRelays = city.relays.filterValidRelays() for (relay in validCityRelays) { relays.add( @@ -47,7 +43,10 @@ fun RelayList.toRelayCountries( relay.hostname ), locationName = "${city.name} (${relay.hostname})", - active = relay.active + active = relay.active, + providerName = relay.provider, + ownership = + if (relay.owned) Ownership.MullvadOwned else Ownership.Rented ) ) } @@ -172,25 +171,40 @@ fun List.filterOnSearchTerm( } } -private fun List.filterValidRelays( +private fun List.filterValidRelays(): List = filter { + it.isWireguardRelay +} + +fun List.filterOnOwnershipAndProviders( ownership: Constraint, providers: Constraint -): List = - filter { it.isWireguardRelay } - .filter { +): List { + return map { country -> + val cities = + country.cities.map { city -> + val relays = + city.relays.filterRelayByOwnershipAndProviders(ownership, providers) + city.copy(relays = relays) + } + country.copy(cities = cities.filter { it.relays.isNotEmpty() }) + } + .filter { it.cities.isNotEmpty() } +} + +private fun List.filterRelayByOwnershipAndProviders( + ownership: Constraint, + providers: Constraint +): List = + filter { when (ownership) { is Constraint.Any -> true - is Constraint.Only -> - when (ownership.value) { - Ownership.MullvadOwned -> it.owned - Ownership.Rented -> !it.owned - } + is Constraint.Only -> it.ownership == ownership.value } } .filter { relay -> when (providers) { is Constraint.Any -> true - is Constraint.Only -> providers.value.providers.contains(relay.provider) + is Constraint.Only -> providers.value.providers.contains(relay.providerName) } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt index 4957818283f7..bdeaac0d0c3f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/RelayListUseCase.kt @@ -9,6 +9,7 @@ import net.mullvad.mullvadvpn.model.RelaySettings import net.mullvad.mullvadvpn.model.WireguardConstraints import net.mullvad.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.relaylist.RelayList +import net.mullvad.mullvadvpn.relaylist.filterOnOwnershipAndProviders import net.mullvad.mullvadvpn.relaylist.findItemForGeographicLocationConstraint import net.mullvad.mullvadvpn.relaylist.toRelayCountries import net.mullvad.mullvadvpn.relaylist.toRelayItemLists @@ -36,22 +37,29 @@ class RelayListUseCase( settings?.relaySettings?.relayConstraints()?.ownership ?: Constraint.Any() val providers = settings?.relaySettings?.relayConstraints()?.providers ?: Constraint.Any() - val relayCountries = - relayList.toRelayCountries(ownership = ownership, providers = providers) + val relayCountries = relayList.toRelayCountries() val customLists = settings?.customLists?.customLists?.toRelayItemLists(relayCountries) ?: emptyList() + val relayCountriesFiltered = + relayCountries.filterOnOwnershipAndProviders(ownership, providers) val selectedItem = findSelectedRelayItem( relaySettings = settings?.relaySettings, - relayCountries = relayCountries, + relayCountries = relayCountriesFiltered, customLists = customLists, ) - RelayList(customLists, relayCountries, selectedItem) + RelayList( + customLists = customLists, + allCountries = relayCountries, + filteredCountries = relayCountriesFiltered, + selectedItem = selectedItem + ) } fun selectedRelayItem(): Flow = relayListWithSelection().map { it.selectedItem } - fun relayList(): Flow> = relayListWithSelection().map { it.country } + fun fullRelayList(): Flow> = + relayListWithSelection().map { it.allCountries } fun customLists(): Flow> = relayListWithSelection().map { it.customLists } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt index 8d722325d650..16c86c0d59e3 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt @@ -53,7 +53,7 @@ class CustomListActionUseCase( ) val locationNames = relayListUseCase - .relayList() + .fullRelayList() .firstOrNull() ?.getRelayItemsByCodes(action.locations) ?.map { it.name } @@ -61,7 +61,7 @@ class CustomListActionUseCase( CustomListResult.Created( id = result.id, name = action.name, - locationName = locationNames?.first(), + locationName = locationNames?.firstOrNull(), undo = action.not(result.id) ) ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt index 5efba5321ee3..cdbcebbb8369 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt @@ -37,7 +37,7 @@ class CustomListLocationsViewModel( private val _searchTerm = MutableStateFlow(EMPTY_SEARCH_TERM) val uiState = - combine(relayListUseCase.relayList(), _searchTerm, _selectedLocations) { + combine(relayListUseCase.fullRelayList(), _searchTerm, _selectedLocations) { relayCountries, searchTerm, selectedLocations -> diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt index 15df90be9e4c..586bbf8bc172 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt @@ -35,6 +35,7 @@ class SelectLocationViewModel( ) : ViewModel() { private val _searchTerm = MutableStateFlow(EMPTY_SEARCH_TERM) + @Suppress("DestructuringDeclarationWithTooManyEntries") val uiState = combine( relayListUseCase.relayListWithSelection(), @@ -43,7 +44,7 @@ class SelectLocationViewModel( relayListFilterUseCase.availableProviders(), relayListFilterUseCase.selectedProviders(), ) { - (customLists, relayCountries, selectedItem), + (customLists, _, relayCountries, selectedItem), searchTerm, selectedOwnership, allProviders, @@ -63,7 +64,15 @@ class SelectLocationViewModel( val filteredRelayCountries = relayCountries.filterOnSearchTerm(searchTerm, selectedItem) - val filteredCustomLists = customLists.filterOnSearchTerm(searchTerm) + val filteredCustomLists = + customLists.filterOnSearchTerm(searchTerm).map { customList -> + customList.copy( + locations = + customList.locations.filter { location -> + filteredRelayCountries.any { it.code == location.code } + } + ) + } SelectLocationUiState.Content( searchTerm = searchTerm, From 2e4bae97bc8a94b2c82710e703629d7dd3683715 Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Tue, 16 Apr 2024 14:13:46 +0200 Subject: [PATCH 2/3] Fix ui tests --- .../net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt index fd4a97a1d251..2adfa22220bd 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/data/DummyRelayItems.kt @@ -1,6 +1,5 @@ package net.mullvad.mullvadvpn.compose.data -import net.mullvad.mullvadvpn.model.Constraint import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.PortRange import net.mullvad.mullvadvpn.model.RelayEndpointData @@ -43,7 +42,7 @@ val DUMMY_RELAY_COUNTRIES = arrayListOf(DUMMY_RELAY_COUNTRY_1, DUMMY_RELAY_COUNTRY_2), DUMMY_WIREGUARD_ENDPOINT_DATA, ) - .toRelayCountries(ownership = Constraint.Any(), providers = Constraint.Any()) + .toRelayCountries() val DUMMY_CUSTOM_LISTS = listOf( From 9a335754d64f1e819bd4dac4753d8a91962ca2cd Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Tue, 16 Apr 2024 14:14:00 +0200 Subject: [PATCH 3/3] Fix unit tests --- .../relaylist/RelayNameComparatorTest.kt | 73 +++++++++++++++++-- .../usecase/CustomListActionUseCaseTest.kt | 2 +- .../CustomListLocationsViewModelTest.kt | 7 +- .../viewmodel/SelectLocationViewModelTest.kt | 21 +++--- 4 files changed, 85 insertions(+), 18 deletions(-) diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt index 1532328729ce..eb66c2d4f907 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.relaylist import io.mockk.mockk import io.mockk.unmockkAll +import net.mullvad.mullvadvpn.model.Ownership import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test @@ -21,6 +22,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay10 = RelayItem.Relay( @@ -28,6 +31,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relay9 assertOrderBothDirection relay10 @@ -41,6 +46,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay9b = RelayItem.Relay( @@ -48,6 +55,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) assertTrue(RelayNameComparator.compare(relay9a, relay9b) == 0) @@ -57,13 +66,41 @@ class RelayNameComparatorTest { @Test fun `comparator should be able to handle name of only numbers`() { val relay001 = - RelayItem.Relay(name = "001", location = mockk(), locationName = "mock", active = false) + RelayItem.Relay( + name = "001", + location = mockk(), + locationName = "mock", + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned + ) val relay1 = - RelayItem.Relay(name = "1", location = mockk(), locationName = "mock", active = false) + RelayItem.Relay( + name = "1", + location = mockk(), + locationName = "mock", + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned + ) val relay3 = - RelayItem.Relay(name = "3", location = mockk(), locationName = "mock", active = false) + RelayItem.Relay( + name = "3", + location = mockk(), + locationName = "mock", + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned + ) val relay100 = - RelayItem.Relay(name = "100", location = mockk(), locationName = "mock", active = false) + RelayItem.Relay( + name = "100", + location = mockk(), + locationName = "mock", + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned + ) relay001 assertOrderBothDirection relay1 relay001 assertOrderBothDirection relay3 @@ -79,6 +116,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay9b = RelayItem.Relay( @@ -86,6 +125,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) assertTrue(RelayNameComparator.compare(relay9a, relay9b) == 0) @@ -100,6 +141,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay005 = RelayItem.Relay( @@ -107,6 +150,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relay001 assertOrderBothDirection relay005 @@ -120,6 +165,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relayAr8 = RelayItem.Relay( @@ -127,6 +174,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relaySe5 = RelayItem.Relay( @@ -134,6 +183,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relaySe10 = RelayItem.Relay( @@ -141,6 +192,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relayAr2 assertOrderBothDirection relayAr8 @@ -155,7 +208,9 @@ class RelayNameComparatorTest { name = "se2-cloud", location = mockk(), locationName = "mock", - active = false + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay2w = RelayItem.Relay( @@ -163,6 +218,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relay2c assertOrderBothDirection relay2w @@ -175,7 +232,9 @@ class RelayNameComparatorTest { name = "se22", location = mockk(), locationName = "mock", - active = false + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay22b = RelayItem.Relay( @@ -183,6 +242,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relay22a assertOrderBothDirection relay22b diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt index fdcb4170f00f..4dfb95768bd2 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt @@ -71,7 +71,7 @@ class CustomListActionUseCaseTest { listOf(locationCode) ) } returns UpdateCustomListResult.Ok - coEvery { mockRelayListUseCase.relayList() } returns flowOf(mockLocations) + coEvery { mockRelayListUseCase.fullRelayList() } returns flowOf(mockLocations) every { mockLocations.getRelayItemsByCodes(listOf(locationCode)) } returns mockLocations // Act diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt index df10ba96c4e6..d21789d36f35 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt @@ -12,6 +12,7 @@ import net.mullvad.mullvadvpn.compose.communication.CustomListResult import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule import net.mullvad.mullvadvpn.model.GeographicLocationConstraint +import net.mullvad.mullvadvpn.model.Ownership import net.mullvad.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.relaylist.descendants import net.mullvad.mullvadvpn.usecase.RelayListUseCase @@ -31,7 +32,7 @@ class CustomListLocationsViewModelTest { @BeforeEach fun setup() { - every { mockRelayListUseCase.relayList() } returns relayListFlow + every { mockRelayListUseCase.fullRelayList() } returns relayListFlow every { mockRelayListUseCase.customLists() } returns customListFlow } @@ -283,7 +284,9 @@ class CustomListLocationsViewModelTest { "SE", "GBG", "gbg-1" - ) + ), + providerName = "Provider", + ownership = Ownership.MullvadOwned ) ) ) 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 41bff94ccd12..6522892ec2f6 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 @@ -49,7 +49,7 @@ class SelectLocationViewModelTest { private val mockServiceConnectionManager: ServiceConnectionManager = mockk() private lateinit var viewModel: SelectLocationViewModel private val relayListWithSelectionFlow = - MutableStateFlow(RelayList(emptyList(), emptyList(), null)) + MutableStateFlow(RelayList(emptyList(), emptyList(), emptyList(), null)) private val mockRelayListUseCase: RelayListUseCase = mockk() private val mockCustomListActionUseCase: CustomListActionUseCase = mockk(relaxed = true) private val selectedOwnership = MutableStateFlow>(Constraint.Any()) @@ -93,10 +93,11 @@ class SelectLocationViewModelTest { fun `given relayListWithSelection emits update uiState should contain new update`() = runTest { // Arrange val mockCountries = listOf(mockk(), mockk()) - val mockCustomList = listOf(mockk()) + val mockCustomList = listOf(mockk(relaxed = true)) val selectedItem: RelayItem = mockk() every { mockCountries.filterOnSearchTerm(any(), selectedItem) } returns mockCountries - relayListWithSelectionFlow.value = RelayList(mockCustomList, mockCountries, selectedItem) + relayListWithSelectionFlow.value = + RelayList(mockCustomList, mockCountries, mockCountries, selectedItem) // Act, Assert viewModel.uiState.test { @@ -111,12 +112,12 @@ class SelectLocationViewModelTest { fun `given relayListWithSelection emits update with no selections selectedItem should be null`() = runTest { // Arrange - val mockCustomList = listOf(mockk()) + val mockCustomList = listOf(mockk(relaxed = true)) val mockCountries = listOf(mockk(), mockk()) val selectedItem: RelayItem? = null every { mockCountries.filterOnSearchTerm(any(), selectedItem) } returns mockCountries relayListWithSelectionFlow.value = - RelayList(mockCustomList, mockCountries, selectedItem) + RelayList(mockCustomList, mockCountries, mockCountries, selectedItem) // Act, Assert viewModel.uiState.test { @@ -155,7 +156,7 @@ class SelectLocationViewModelTest { @Test fun `on onSearchTermInput call uiState should emit with filtered countries`() = runTest { // Arrange - val mockCustomList = listOf(mockk()) + val mockCustomList = listOf(mockk(relaxed = true)) val mockCountries = listOf(mockk(), mockk()) val selectedItem: RelayItem? = null val mockRelayList: List = mockk(relaxed = true) @@ -163,7 +164,8 @@ class SelectLocationViewModelTest { every { mockRelayList.filterOnSearchTerm(mockSearchString, selectedItem) } returns mockCountries every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList - relayListWithSelectionFlow.value = RelayList(mockCustomList, mockRelayList, selectedItem) + relayListWithSelectionFlow.value = + RelayList(mockCustomList, mockRelayList, mockRelayList, selectedItem) // Act, Assert viewModel.uiState.test { @@ -184,7 +186,7 @@ class SelectLocationViewModelTest { @Test fun `when onSearchTermInput returns empty result uiState should return empty list`() = runTest { // Arrange - val mockCustomList = listOf(mockk()) + val mockCustomList = listOf(mockk(relaxed = true)) val mockCountries = emptyList() val selectedItem: RelayItem? = null val mockRelayList: List = mockk(relaxed = true) @@ -192,7 +194,8 @@ class SelectLocationViewModelTest { every { mockRelayList.filterOnSearchTerm(mockSearchString, selectedItem) } returns mockCountries every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList - relayListWithSelectionFlow.value = RelayList(mockCustomList, mockRelayList, selectedItem) + relayListWithSelectionFlow.value = + RelayList(mockCustomList, mockRelayList, mockRelayList, selectedItem) // Act, Assert viewModel.uiState.test {