summaryrefslogtreecommitdiffhomepage
path: root/android/app/src/test
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-09-10 08:43:26 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2024-09-10 11:09:34 +0200
commit47ae1396fb38703c78166f446797641102f76cfc (patch)
treef40985c077c53bd657731d846cf2001a063a6767 /android/app/src/test
parentc107177b86906b94ac85387c0d7fe14c63d3427b (diff)
downloadmullvadvpn-47ae1396fb38703c78166f446797641102f76cfc.tar.xz
mullvadvpn-47ae1396fb38703c78166f446797641102f76cfc.zip
Add test for adding exactly one location to a custom list
Diffstat (limited to 'android/app/src/test')
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt51
1 files changed, 51 insertions, 0 deletions
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,
+ )
}
}