Skip to content

Commit 0052616

Browse files
committed
Fix and add unit tests for custom list location change
1 parent df43b82 commit 0052616

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt

+49-4
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,29 @@ class SelectLocationViewModelTest {
252252
@Test
253253
fun `after adding a location to a list should emit location added side effect`() = runTest {
254254
// Arrange
255-
val expectedResult: LocationsChanged = mockk()
255+
val locationName = "Country"
256+
val customListName = CustomListName.fromString("custom")
257+
val undoAction: CustomListAction.UpdateLocations = mockk()
256258
val location: RelayItem.Location.Country = mockk {
257259
every { id } returns GeoLocationId.Country("se")
258-
every { name } returns "Country"
260+
every { name } returns locationName
259261
every { descendants() } returns emptyList()
260262
}
261263
val customList =
262264
RelayItem.CustomList(
263265
id = CustomListId("1"),
264-
customListName = CustomListName.fromString("custom"),
266+
customListName = customListName,
265267
locations = emptyList(),
266268
expanded = false
267269
)
270+
val expectedResult =
271+
LocationsChanged(
272+
name = customListName,
273+
locationNamesAdded = listOf(locationName),
274+
undo = undoAction
275+
)
268276
coEvery { mockCustomListActionUseCase(any<CustomListAction.UpdateLocations>()) } returns
269-
expectedResult.right()
277+
LocationsChanged(name = customListName, undo = undoAction).right()
270278

271279
// Act, Assert
272280
viewModel.uiSideEffect.test {
@@ -277,6 +285,43 @@ class SelectLocationViewModelTest {
277285
}
278286
}
279287

288+
@Test
289+
fun `after removing a location from a list should emit location removed side effect`() =
290+
runTest {
291+
// Arrange
292+
val locationName = "Country"
293+
val customListName = CustomListName.fromString("custom")
294+
val undoAction: CustomListAction.UpdateLocations = mockk()
295+
val location: RelayItem.Location.Country = mockk {
296+
every { id } returns GeoLocationId.Country("se")
297+
every { name } returns locationName
298+
every { descendants() } returns emptyList()
299+
}
300+
val customList =
301+
RelayItem.CustomList(
302+
id = CustomListId("1"),
303+
customListName = customListName,
304+
locations = emptyList(),
305+
expanded = false
306+
)
307+
val expectedResult =
308+
LocationsChanged(
309+
name = customListName,
310+
locationNamesRemoved = listOf(locationName),
311+
undo = undoAction
312+
)
313+
coEvery { mockCustomListActionUseCase(any<CustomListAction.UpdateLocations>()) } returns
314+
LocationsChanged(name = customListName, undo = undoAction).right()
315+
316+
// Act, Assert
317+
viewModel.uiSideEffect.test {
318+
viewModel.removeLocationFromList(item = location, customList = customList)
319+
val sideEffect = awaitItem()
320+
assertIs<SelectLocationSideEffect.LocationRemovedFromCustomList>(sideEffect)
321+
assertEquals(expectedResult, sideEffect.result)
322+
}
323+
}
324+
280325
companion object {
281326
private const val RELAY_LIST_EXTENSIONS =
282327
"net.mullvad.mullvadvpn.relaylist.RelayListExtensionsKt"

0 commit comments

Comments
 (0)