@@ -252,21 +252,29 @@ class SelectLocationViewModelTest {
252
252
@Test
253
253
fun `after adding a location to a list should emit location added side effect` () = runTest {
254
254
// Arrange
255
- val expectedResult: LocationsChanged = mockk()
255
+ val locationName = " Country"
256
+ val customListName = CustomListName .fromString(" custom" )
257
+ val undoAction: CustomListAction .UpdateLocations = mockk()
256
258
val location: RelayItem .Location .Country = mockk {
257
259
every { id } returns GeoLocationId .Country (" se" )
258
- every { name } returns " Country "
260
+ every { name } returns locationName
259
261
every { descendants() } returns emptyList()
260
262
}
261
263
val customList =
262
264
RelayItem .CustomList (
263
265
id = CustomListId (" 1" ),
264
- customListName = CustomListName .fromString( " custom " ) ,
266
+ customListName = customListName ,
265
267
locations = emptyList(),
266
268
expanded = false
267
269
)
270
+ val expectedResult =
271
+ LocationsChanged (
272
+ name = customListName,
273
+ locationNamesAdded = listOf (locationName),
274
+ undo = undoAction
275
+ )
268
276
coEvery { mockCustomListActionUseCase(any<CustomListAction .UpdateLocations >()) } returns
269
- expectedResult .right()
277
+ LocationsChanged (name = customListName, undo = undoAction) .right()
270
278
271
279
// Act, Assert
272
280
viewModel.uiSideEffect.test {
@@ -277,6 +285,43 @@ class SelectLocationViewModelTest {
277
285
}
278
286
}
279
287
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
+
280
325
companion object {
281
326
private const val RELAY_LIST_EXTENSIONS =
282
327
" net.mullvad.mullvadvpn.relaylist.RelayListExtensionsKt"
0 commit comments