@@ -252,20 +252,37 @@ 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 customListId = CustomListId (" 1" )
256
+ val addedLocationsId = GeoLocationId .Country (" se" )
257
+ val customListName = CustomListName .fromString(" custom" )
256
258
val location: RelayItem .Location .Country = mockk {
257
259
every { id } returns GeoLocationId .Country (" se" )
260
+ every { name } returns " Sweden"
258
261
every { descendants() } returns emptyList()
259
262
}
260
263
val customList =
261
264
RelayItem .CustomList (
262
265
id = CustomListId (" 1" ),
263
- customListName = CustomListName .fromString( " custom " ) ,
266
+ customListName = customListName ,
264
267
locations = emptyList(),
265
268
expanded = false
266
269
)
270
+ val expectedResult =
271
+ LocationsChanged (
272
+ id = customListId,
273
+ name = customListName,
274
+ locations = listOf (addedLocationsId),
275
+ oldLocations = emptyList(),
276
+ )
277
+
267
278
coEvery { mockCustomListActionUseCase(any<CustomListAction .UpdateLocations >()) } returns
268
- expectedResult.right()
279
+ LocationsChanged (
280
+ id = customListId,
281
+ name = customListName,
282
+ locations = listOf (addedLocationsId),
283
+ oldLocations = emptyList()
284
+ )
285
+ .right()
269
286
270
287
// Act, Assert
271
288
viewModel.uiSideEffect.test {
@@ -276,6 +293,51 @@ class SelectLocationViewModelTest {
276
293
}
277
294
}
278
295
296
+ @Test
297
+ fun `after removing a location from a list should emit location removed side effect` () =
298
+ runTest {
299
+ // Arrange
300
+ val locationName = " Sweden"
301
+ val customListId = CustomListId (" 1" )
302
+ val removedLocationsId = GeoLocationId .Country (" se" )
303
+ val customListName = CustomListName .fromString(" custom" )
304
+ val location: RelayItem .Location .Country = mockk {
305
+ every { id } returns removedLocationsId
306
+ every { name } returns locationName
307
+ every { descendants() } returns emptyList()
308
+ }
309
+ val customList =
310
+ RelayItem .CustomList (
311
+ id = customListId,
312
+ customListName = customListName,
313
+ locations = emptyList(),
314
+ expanded = false
315
+ )
316
+ val expectedResult =
317
+ LocationsChanged (
318
+ id = customListId,
319
+ name = customListName,
320
+ locations = emptyList(),
321
+ oldLocations = listOf (removedLocationsId),
322
+ )
323
+ coEvery { mockCustomListActionUseCase(any<CustomListAction .UpdateLocations >()) } returns
324
+ LocationsChanged (
325
+ id = customListId,
326
+ name = customListName,
327
+ locations = emptyList(),
328
+ oldLocations = listOf (removedLocationsId),
329
+ )
330
+ .right()
331
+
332
+ // Act, Assert
333
+ viewModel.uiSideEffect.test {
334
+ viewModel.removeLocationFromList(item = location, customList = customList)
335
+ val sideEffect = awaitItem()
336
+ assertIs<SelectLocationSideEffect .LocationRemovedFromCustomList >(sideEffect)
337
+ assertEquals(expectedResult, sideEffect.result)
338
+ }
339
+ }
340
+
279
341
companion object {
280
342
private const val RELAY_LIST_EXTENSIONS =
281
343
" net.mullvad.mullvadvpn.relaylist.RelayListExtensionsKt"
0 commit comments