@@ -120,14 +120,12 @@ class SelectLocationViewModelTest {
120
120
assertIs<SelectLocationUiState .Content >(actualState)
121
121
assertLists(
122
122
testCountries.map { it.id },
123
- actualState.relayListItems.mapNotNull { it.relayItemId() }
124
- )
123
+ actualState.relayListItems.mapNotNull { it.relayItemId() })
125
124
assertTrue(
126
125
actualState.relayListItems
127
126
.filterIsInstance<RelayListItem .SelectableItem >()
128
127
.first { it.relayItemId() == selectedId }
129
- .isSelected
130
- )
128
+ .isSelected)
131
129
}
132
130
}
133
131
@@ -143,13 +141,11 @@ class SelectLocationViewModelTest {
143
141
assertIs<SelectLocationUiState .Content >(actualState)
144
142
assertLists(
145
143
testCountries.map { it.id },
146
- actualState.relayListItems.mapNotNull { it.relayItemId() }
147
- )
144
+ actualState.relayListItems.mapNotNull { it.relayItemId() })
148
145
assertTrue(
149
146
actualState.relayListItems.filterIsInstance<RelayListItem .SelectableItem >().all {
150
147
! it.isSelected
151
- }
152
- )
148
+ })
153
149
}
154
150
}
155
151
@@ -174,13 +170,12 @@ class SelectLocationViewModelTest {
174
170
@Test
175
171
fun `on onSearchTermInput call uiState should emit with filtered countries` () = runTest {
176
172
// Arrange
177
- val mockCustomList = listOf<RelayItem .CustomList >(mockk(relaxed = true ))
178
173
val mockCountries = listOf<RelayItem .Location .Country >(mockk(), mockk())
179
174
val selectedItem: RelayItemId ? = null
180
175
val mockRelayList: List <RelayItem .Location .Country > = mockk(relaxed = true )
181
- val mockSearchString = " SEARCH "
176
+ val mockSearchString = " got "
182
177
every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList
183
- filteredRelayList.value = mockRelayList
178
+ filteredRelayList.value = testCountries
184
179
selectedRelayItemFlow.value = Constraint .Any
185
180
186
181
// Act, Assert
@@ -202,12 +197,8 @@ class SelectLocationViewModelTest {
202
197
@Test
203
198
fun `when onSearchTermInput returns empty result uiState should return empty list` () = runTest {
204
199
// Arrange
205
- val mockCustomList = listOf<RelayItem .CustomList >(mockk(relaxed = true ))
206
- val mockCountries = emptyList<RelayItem .Location .Country >()
207
- val selectedItem: RelayItemId ? = null
208
- val mockRelayList: List <RelayItem .Location .Country > = mockk(relaxed = true )
200
+ filteredRelayList.value = testCountries
209
201
val mockSearchString = " SEARCH"
210
- every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList
211
202
212
203
// Act, Assert
213
204
viewModel.uiState.test {
@@ -217,10 +208,16 @@ class SelectLocationViewModelTest {
217
208
// Update search string
218
209
viewModel.onSearchTermInput(mockSearchString)
219
210
211
+ // We get some unnecessary emissions for now
212
+ awaitItem()
213
+ awaitItem()
214
+
220
215
// Assert
221
216
val actualState = awaitItem()
222
217
assertIs<SelectLocationUiState .Content >(actualState)
223
- assertEquals(mockSearchString, actualState.searchTerm)
218
+ assertEquals(
219
+ listOf (RelayListItem .LocationsEmptyText (mockSearchString)),
220
+ actualState.relayListItems)
224
221
}
225
222
}
226
223
@@ -280,8 +277,7 @@ class SelectLocationViewModelTest {
280
277
CustomList (
281
278
id = CustomListId (" 1" ),
282
279
name = CustomListName .fromString(" custom" ),
283
- locations = emptyList()
284
- ),
280
+ locations = emptyList()),
285
281
locations = emptyList(),
286
282
)
287
283
coEvery { mockCustomListActionUseCase(any<CustomListAction .UpdateLocations >()) } returns
@@ -317,8 +313,14 @@ class SelectLocationViewModelTest {
317
313
318
314
private val testCountries =
319
315
listOf<RelayItem .Location .Country >(
320
- RelayItem .Location .Country (id = GeoLocationId .Country (" se" ), " Sweden" , emptyList()),
321
- RelayItem .Location .Country (id = GeoLocationId .Country (" no" ), " Norway" , emptyList())
322
- )
316
+ RelayItem .Location .Country (
317
+ id = GeoLocationId .Country (" se" ),
318
+ " Sweden" ,
319
+ listOf (
320
+ RelayItem .Location .City (
321
+ id = GeoLocationId .City (GeoLocationId .Country (" se" ), " got" ),
322
+ " Gothenburg" ,
323
+ emptyList()))),
324
+ RelayItem .Location .Country (id = GeoLocationId .Country (" no" ), " Norway" , emptyList()))
323
325
}
324
326
}
0 commit comments