@@ -10,6 +10,7 @@ import kotlin.test.assertIs
10
10
import kotlinx.coroutines.flow.MutableStateFlow
11
11
import kotlinx.coroutines.test.runTest
12
12
import net.mullvad.mullvadvpn.compose.communication.CustomListAction
13
+ import net.mullvad.mullvadvpn.compose.communication.CustomListActionResultData
13
14
import net.mullvad.mullvadvpn.compose.communication.LocationsChanged
14
15
import net.mullvad.mullvadvpn.compose.screen.CustomListLocationsNavArgs
15
16
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
@@ -180,40 +181,57 @@ class CustomListLocationsViewModelTest {
180
181
}
181
182
182
183
@Test
183
- fun `given new list true when saving successfully should emit close screen side effect ` () =
184
+ fun `given new list true when saving successfully should emit return with result data ` () =
184
185
runTest {
185
186
// Arrange
186
187
val customListId = CustomListId (" 1" )
188
+ val customListName = CustomListName .fromString(" name" )
187
189
val newList = true
188
- val expectedResult : LocationsChanged = mockk()
190
+ val locationChangedMock : LocationsChanged = mockk()
189
191
coEvery { mockCustomListUseCase(any<CustomListAction .UpdateLocations >()) } returns
190
- expectedResult.right()
192
+ locationChangedMock.right()
193
+ every { locationChangedMock.name } returns customListName
194
+ every { locationChangedMock.id } returns customListId
191
195
val viewModel = createViewModel(customListId, newList)
192
196
193
197
// Act, Assert
194
198
viewModel.uiSideEffect.test {
195
199
viewModel.save()
196
200
val sideEffect = awaitItem()
197
- assertIs<CustomListLocationsSideEffect .CloseScreen >(sideEffect)
201
+ assertIs<CustomListLocationsSideEffect .ReturnWithResultData >(sideEffect)
198
202
}
199
203
}
200
204
201
205
@Test
202
- fun `given new list false when saving successfully should emit return with result side effect ` () =
206
+ fun `given new list false when saving successfully should emit return with result data ` () =
203
207
runTest {
204
208
// Arrange
205
209
val customListId = CustomListId (" 1" )
210
+ val customListName = CustomListName .fromString(" name" )
211
+ val mockUndo: CustomListAction .UpdateLocations = mockk()
212
+ val addedLocations: List <GeoLocationId > = listOf (mockk())
213
+ val removedLocations: List <GeoLocationId > = listOf (mockk())
206
214
val newList = false
207
- val expectedResult: LocationsChanged = mockk()
215
+ val locationsChangedMock: LocationsChanged = mockk()
216
+ val expectedResult =
217
+ CustomListActionResultData .LocationChanged (
218
+ customListName = customListName,
219
+ undo = mockUndo
220
+ )
208
221
coEvery { mockCustomListUseCase(any<CustomListAction .UpdateLocations >()) } returns
209
- expectedResult.right()
222
+ locationsChangedMock.right()
223
+ every { locationsChangedMock.id } returns customListId
224
+ every { locationsChangedMock.name } returns customListName
225
+ every { locationsChangedMock.addedLocations } returns addedLocations
226
+ every { locationsChangedMock.removedLocations } returns removedLocations
227
+ every { locationsChangedMock.undo } returns mockUndo
210
228
val viewModel = createViewModel(customListId, newList)
211
229
212
230
// Act, Assert
213
231
viewModel.uiSideEffect.test {
214
232
viewModel.save()
215
233
val sideEffect = awaitItem()
216
- assertIs<CustomListLocationsSideEffect .ReturnWithResult >(sideEffect)
234
+ assertIs<CustomListLocationsSideEffect .ReturnWithResultData >(sideEffect)
217
235
assertEquals(expectedResult, sideEffect.result)
218
236
}
219
237
}
0 commit comments