summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson@mullvad.net>2024-09-10 11:17:52 +0200
committerDavid Göransson <david.goransson@mullvad.net>2024-09-10 11:17:52 +0200
commit49dcbd2b166b81b31256282e8a18684cc91c9fac (patch)
treef40985c077c53bd657731d846cf2001a063a6767
parentd090bd05f278cfe0fef7bae417b2153c8549cc15 (diff)
parent47ae1396fb38703c78166f446797641102f76cfc (diff)
downloadmullvadvpn-49dcbd2b166b81b31256282e8a18684cc91c9fac.tar.xz
mullvadvpn-49dcbd2b166b81b31256282e8a18684cc91c9fac.zip
Merge branch 'crash-in-customlistlocationviewmodel-droid-1317'
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt2
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt51
2 files changed, 52 insertions, 1 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 df6037a0b4..271e7cd7f5 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
@@ -289,7 +289,7 @@ class CustomListLocationsViewModel(
success.addedLocations.size == 1 && success.removedLocations.isEmpty() ->
CustomListActionResultData.Success.LocationAdded(
customListName = success.name,
- relayListRepository.find(success.removedLocations.first())!!.name,
+ relayListRepository.find(success.addedLocations.first())!!.name,
undo = success.undo,
)
success.removedLocations.size == 1 && success.addedLocations.isEmpty() ->
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 1e0de9c96e..75b8deca8f 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
@@ -270,6 +270,46 @@ class CustomListLocationsViewModelTest {
}
}
+ @Test
+ fun `given not new list and adding exactly one location and removing zero locations should emit location added`() =
+ runTest {
+ // Arrange
+ val customListId = CustomListId("1")
+ val customListName = CustomListName.fromString("name")
+ val undo =
+ CustomListAction.UpdateLocations(
+ id = customListId,
+ locations = listOf(DUMMY_COUNTRIES[0].id),
+ )
+ val expectedResult =
+ CustomListActionResultData.Success.LocationAdded(
+ customListName = customListName,
+ locationName = DUMMY_RELAY.name,
+ undo = undo,
+ )
+ selectedLocationsFlow.value = DUMMY_COUNTRIES
+ coEvery { mockCustomListUseCase(any<CustomListAction.UpdateLocations>()) } returns
+ LocationsChanged(
+ id = customListId,
+ name = customListName,
+ locations = listOf(DUMMY_COUNTRIES[0].id, DUMMY_RELAY.id),
+ oldLocations = listOf(DUMMY_COUNTRIES[0].id),
+ )
+ .right()
+ coEvery { mockRelayListRepository.find(DUMMY_RELAY.id) } returns DUMMY_RELAY
+
+ val viewModel = createViewModel(customListId = customListId, newList = false)
+
+ // Act, Assert
+ viewModel.uiSideEffect.test {
+ viewModel.onRelaySelectionClick(DUMMY_RELAY, true)
+ viewModel.save()
+ val sideEffect = awaitItem()
+ assertIs<CustomListLocationsSideEffect.ReturnWithResultData>(sideEffect)
+ assertEquals(expectedResult, sideEffect.result)
+ }
+ }
+
private fun createViewModel(
customListId: CustomListId,
newList: Boolean,
@@ -329,5 +369,16 @@ class CustomListLocationsViewModelTest {
),
)
)
+ private val DUMMY_RELAY =
+ RelayItem.Location.Relay(
+ id =
+ GeoLocationId.Hostname(
+ GeoLocationId.City(GeoLocationId.Country("DK"), "CPH"),
+ "cph-1",
+ ),
+ active = true,
+ provider = Provider(ProviderId("Provider"), ownership = Ownership.MullvadOwned),
+ daita = false,
+ )
}
}