diff options
| author | David Göransson <david.goransson@mullvad.net> | 2024-07-25 16:44:48 +0200 |
|---|---|---|
| committer | David Göransson <david.goransson@mullvad.net> | 2024-07-25 16:44:48 +0200 |
| commit | e6313c5dc104004e66b101622362d6f420e434b0 (patch) | |
| tree | 55e3795ee8fa7542e579c16a8c44338f2756d397 /android/app | |
| parent | 0da1615d60ffb231fdcb9574a2ea6ba96521d1e9 (diff) | |
| parent | a163fd97f1595542ac014f4011e7003449299703 (diff) | |
| download | mullvadvpn-e6313c5dc104004e66b101622362d6f420e434b0.tar.xz mullvadvpn-e6313c5dc104004e66b101622362d6f420e434b0.zip | |
Merge branch 'fix-edit-location-inital-expand'
Diffstat (limited to 'android/app')
2 files changed, 11 insertions, 6 deletions
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 3df2b2f623..7fa101a8e3 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 @@ -97,8 +97,9 @@ class CustomListLocationsViewModel( val (exp, filteredRelayCountries) = relayCountries.newFilterOnSearch(searchTerm) exp.toSet() to filteredRelayCountries } else { - initialExpands((_selectedLocations.value ?: emptyList()).toSet()) to - relayCountries + initialExpands( + _selectedLocations.value?.calculateLocationsToSave() ?: emptyList() + ) to relayCountries } } .onEach { _expandedItems.value = it.first } @@ -223,16 +224,16 @@ class CustomListLocationsViewModel( } private suspend fun fetchInitialSelectedLocations() { - val selectedLocations = - customListRelayItemsUseCase(navArgs.customListId).first().withDescendants().toSet() + val locations = customListRelayItemsUseCase(navArgs.customListId).first() + val selectedLocations = locations.withDescendants().toSet() _initialLocations.value = selectedLocations _selectedLocations.value = selectedLocations // Initial expand - _expandedItems.value = initialExpands(selectedLocations) + _expandedItems.value = initialExpands(locations) } - private fun initialExpands(locations: Set<RelayItem.Location>): Set<RelayItemId> = + private fun initialExpands(locations: List<RelayItem.Location>): Set<RelayItemId> = locations.flatMap { it.id.ancestors() }.toSet() private fun List<RelayItem.Location>.toRelayItems( 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 d2eaedd8c2..f73dbee7a3 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 @@ -133,8 +133,10 @@ class CustomListLocationsViewModelTest { // Act, Assert viewModel.uiState.test { + awaitItem() // Expand country viewModel.onExpand(DUMMY_COUNTRIES[0], true) + awaitItem() // Expand city viewModel.onExpand(DUMMY_COUNTRIES[0].cities[0], true) // Check initial selected @@ -164,8 +166,10 @@ class CustomListLocationsViewModelTest { // Act, Assert viewModel.uiState.test { + awaitItem() // Expand country viewModel.onExpand(DUMMY_COUNTRIES[0], true) + awaitItem() // Expand city viewModel.onExpand(DUMMY_COUNTRIES[0].cities[0], true) // Check initial selected |
