File tree 2 files changed +8
-2
lines changed
main/kotlin/net/mullvad/mullvadvpn/viewmodel
test/kotlin/net/mullvad/mullvadvpn/viewmodel
2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import net.mullvad.mullvadvpn.model.Constraint
19
19
import net.mullvad.mullvadvpn.model.Ownership
20
20
import net.mullvad.mullvadvpn.relaylist.Provider
21
21
import net.mullvad.mullvadvpn.relaylist.RelayItem
22
+ import net.mullvad.mullvadvpn.relaylist.descendants
22
23
import net.mullvad.mullvadvpn.relaylist.filterOnOwnershipAndProvider
23
24
import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm
24
25
import net.mullvad.mullvadvpn.relaylist.toLocationConstraint
@@ -137,7 +138,8 @@ class SelectLocationViewModel(
137
138
138
139
fun addLocationToList (item : RelayItem , customList : RelayItem .CustomList ) {
139
140
viewModelScope.launch {
140
- val newLocations = (customList.locations + item).map { it.code }
141
+ val newLocations =
142
+ (customList.locations + item).filter { it !in item.descendants() }.map { it.code }
141
143
val result =
142
144
customListActionUseCase.performAction(
143
145
CustomListAction .UpdateLocations (customList.id, newLocations)
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import net.mullvad.mullvadvpn.model.Providers
29
29
import net.mullvad.mullvadvpn.relaylist.Provider
30
30
import net.mullvad.mullvadvpn.relaylist.RelayItem
31
31
import net.mullvad.mullvadvpn.relaylist.RelayList
32
+ import net.mullvad.mullvadvpn.relaylist.descendants
32
33
import net.mullvad.mullvadvpn.relaylist.filterOnSearchTerm
33
34
import net.mullvad.mullvadvpn.relaylist.toLocationConstraint
34
35
import net.mullvad.mullvadvpn.ui.serviceconnection.ConnectionProxy
@@ -264,7 +265,10 @@ class SelectLocationViewModelTest {
264
265
fun `after adding a location to a list should emit location added side effect` () = runTest {
265
266
// Arrange
266
267
val expectedResult: CustomListResult .LocationsChanged = mockk()
267
- val location: RelayItem = mockk { every { code } returns " code" }
268
+ val location: RelayItem = mockk {
269
+ every { code } returns " code"
270
+ every { descendants() } returns emptyList()
271
+ }
268
272
val customList: RelayItem .CustomList = mockk {
269
273
every { id } returns " 1"
270
274
every { locations } returns emptyList()
You can’t perform that action at this time.
0 commit comments