diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt | 51 |
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, + ) } } |
