Skip to content

Commit 7456d9b

Browse files
committed
fix some tests
1 parent 8c384c7 commit 7456d9b

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

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

+24-22
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,12 @@ class SelectLocationViewModelTest {
120120
assertIs<SelectLocationUiState.Content>(actualState)
121121
assertLists(
122122
testCountries.map { it.id },
123-
actualState.relayListItems.mapNotNull { it.relayItemId() }
124-
)
123+
actualState.relayListItems.mapNotNull { it.relayItemId() })
125124
assertTrue(
126125
actualState.relayListItems
127126
.filterIsInstance<RelayListItem.SelectableItem>()
128127
.first { it.relayItemId() == selectedId }
129-
.isSelected
130-
)
128+
.isSelected)
131129
}
132130
}
133131

@@ -143,13 +141,11 @@ class SelectLocationViewModelTest {
143141
assertIs<SelectLocationUiState.Content>(actualState)
144142
assertLists(
145143
testCountries.map { it.id },
146-
actualState.relayListItems.mapNotNull { it.relayItemId() }
147-
)
144+
actualState.relayListItems.mapNotNull { it.relayItemId() })
148145
assertTrue(
149146
actualState.relayListItems.filterIsInstance<RelayListItem.SelectableItem>().all {
150147
!it.isSelected
151-
}
152-
)
148+
})
153149
}
154150
}
155151

@@ -174,13 +170,12 @@ class SelectLocationViewModelTest {
174170
@Test
175171
fun `on onSearchTermInput call uiState should emit with filtered countries`() = runTest {
176172
// Arrange
177-
val mockCustomList = listOf<RelayItem.CustomList>(mockk(relaxed = true))
178173
val mockCountries = listOf<RelayItem.Location.Country>(mockk(), mockk())
179174
val selectedItem: RelayItemId? = null
180175
val mockRelayList: List<RelayItem.Location.Country> = mockk(relaxed = true)
181-
val mockSearchString = "SEARCH"
176+
val mockSearchString = "got"
182177
every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList
183-
filteredRelayList.value = mockRelayList
178+
filteredRelayList.value = testCountries
184179
selectedRelayItemFlow.value = Constraint.Any
185180

186181
// Act, Assert
@@ -202,12 +197,8 @@ class SelectLocationViewModelTest {
202197
@Test
203198
fun `when onSearchTermInput returns empty result uiState should return empty list`() = runTest {
204199
// 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
209201
val mockSearchString = "SEARCH"
210-
every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList
211202

212203
// Act, Assert
213204
viewModel.uiState.test {
@@ -217,10 +208,16 @@ class SelectLocationViewModelTest {
217208
// Update search string
218209
viewModel.onSearchTermInput(mockSearchString)
219210

211+
// We get some unnecessary emissions for now
212+
awaitItem()
213+
awaitItem()
214+
220215
// Assert
221216
val actualState = awaitItem()
222217
assertIs<SelectLocationUiState.Content>(actualState)
223-
assertEquals(mockSearchString, actualState.searchTerm)
218+
assertEquals(
219+
listOf(RelayListItem.LocationsEmptyText(mockSearchString)),
220+
actualState.relayListItems)
224221
}
225222
}
226223

@@ -280,8 +277,7 @@ class SelectLocationViewModelTest {
280277
CustomList(
281278
id = CustomListId("1"),
282279
name = CustomListName.fromString("custom"),
283-
locations = emptyList()
284-
),
280+
locations = emptyList()),
285281
locations = emptyList(),
286282
)
287283
coEvery { mockCustomListActionUseCase(any<CustomListAction.UpdateLocations>()) } returns
@@ -317,8 +313,14 @@ class SelectLocationViewModelTest {
317313

318314
private val testCountries =
319315
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()))
323325
}
324326
}

0 commit comments

Comments
 (0)