Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate entries when adding through bottom sheet #6156

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading