Skip to content

Commit

Permalink
Fix duplicate entries when adding through bottom sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Apr 19, 2024
1 parent d54dcc6 commit 98b2df6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import net.mullvad.mullvadvpn.model.Constraint
import net.mullvad.mullvadvpn.model.Ownership
import net.mullvad.mullvadvpn.relaylist.Provider
import net.mullvad.mullvadvpn.relaylist.RelayItem
import net.mullvad.mullvadvpn.relaylist.descendants
import net.mullvad.mullvadvpn.relaylist.filterOnOwnershipAndProvider
import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm
import net.mullvad.mullvadvpn.relaylist.toLocationConstraint
Expand Down Expand Up @@ -137,7 +138,8 @@ class SelectLocationViewModel(

fun addLocationToList(item: RelayItem, customList: RelayItem.CustomList) {
viewModelScope.launch {
val newLocations = (customList.locations + item).map { it.code }
val newLocations =
(customList.locations + item).filter { it !in item.descendants() }.map { it.code }
val result =
customListActionUseCase.performAction(
CustomListAction.UpdateLocations(customList.id, newLocations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import net.mullvad.mullvadvpn.model.Providers
import net.mullvad.mullvadvpn.relaylist.Provider
import net.mullvad.mullvadvpn.relaylist.RelayItem
import net.mullvad.mullvadvpn.relaylist.RelayList
import net.mullvad.mullvadvpn.relaylist.descendants
import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm
import net.mullvad.mullvadvpn.relaylist.toLocationConstraint
import net.mullvad.mullvadvpn.ui.serviceconnection.ConnectionProxy
Expand Down Expand Up @@ -264,7 +265,10 @@ class SelectLocationViewModelTest {
fun `after adding a location to a list should emit location added side effect`() = runTest {
// Arrange
val expectedResult: CustomListResult.LocationsChanged = mockk()
val location: RelayItem = mockk { every { code } returns "code" }
val location: RelayItem = mockk {
every { code } returns "code"
every { descendants() } returns emptyList()
}
val customList: RelayItem.CustomList = mockk {
every { id } returns "1"
every { locations } returns emptyList()
Expand Down

0 comments on commit 98b2df6

Please sign in to comment.