Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Jul 25, 2024
1 parent 8c384c7 commit 7456d9b
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@ class SelectLocationViewModelTest {
assertIs<SelectLocationUiState.Content>(actualState)
assertLists(
testCountries.map { it.id },
actualState.relayListItems.mapNotNull { it.relayItemId() }
)
actualState.relayListItems.mapNotNull { it.relayItemId() })
assertTrue(
actualState.relayListItems
.filterIsInstance<RelayListItem.SelectableItem>()
.first { it.relayItemId() == selectedId }
.isSelected
)
.isSelected)
}
}

Expand All @@ -143,13 +141,11 @@ class SelectLocationViewModelTest {
assertIs<SelectLocationUiState.Content>(actualState)
assertLists(
testCountries.map { it.id },
actualState.relayListItems.mapNotNull { it.relayItemId() }
)
actualState.relayListItems.mapNotNull { it.relayItemId() })
assertTrue(
actualState.relayListItems.filterIsInstance<RelayListItem.SelectableItem>().all {
!it.isSelected
}
)
})
}
}

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

// Act, Assert
Expand All @@ -202,12 +197,8 @@ class SelectLocationViewModelTest {
@Test
fun `when onSearchTermInput returns empty result uiState should return empty list`() = runTest {
// Arrange
val mockCustomList = listOf<RelayItem.CustomList>(mockk(relaxed = true))
val mockCountries = emptyList<RelayItem.Location.Country>()
val selectedItem: RelayItemId? = null
val mockRelayList: List<RelayItem.Location.Country> = mockk(relaxed = true)
filteredRelayList.value = testCountries
val mockSearchString = "SEARCH"
every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList

// Act, Assert
viewModel.uiState.test {
Expand All @@ -217,10 +208,16 @@ class SelectLocationViewModelTest {
// Update search string
viewModel.onSearchTermInput(mockSearchString)

// We get some unnecessary emissions for now
awaitItem()
awaitItem()

// Assert
val actualState = awaitItem()
assertIs<SelectLocationUiState.Content>(actualState)
assertEquals(mockSearchString, actualState.searchTerm)
assertEquals(
listOf(RelayListItem.LocationsEmptyText(mockSearchString)),
actualState.relayListItems)
}
}

Expand Down Expand Up @@ -280,8 +277,7 @@ class SelectLocationViewModelTest {
CustomList(
id = CustomListId("1"),
name = CustomListName.fromString("custom"),
locations = emptyList()
),
locations = emptyList()),
locations = emptyList(),
)
coEvery { mockCustomListActionUseCase(any<CustomListAction.UpdateLocations>()) } returns
Expand Down Expand Up @@ -317,8 +313,14 @@ class SelectLocationViewModelTest {

private val testCountries =
listOf<RelayItem.Location.Country>(
RelayItem.Location.Country(id = GeoLocationId.Country("se"), "Sweden", emptyList()),
RelayItem.Location.Country(id = GeoLocationId.Country("no"), "Norway", emptyList())
)
RelayItem.Location.Country(
id = GeoLocationId.Country("se"),
"Sweden",
listOf(
RelayItem.Location.City(
id = GeoLocationId.City(GeoLocationId.Country("se"), "got"),
"Gothenburg",
emptyList()))),
RelayItem.Location.Country(id = GeoLocationId.Country("no"), "Norway", emptyList()))
}
}

0 comments on commit 7456d9b

Please sign in to comment.