Skip to content

Commit

Permalink
Merge branch 'empty-state-updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
shorthouse committed Mar 21, 2024
2 parents f3c2385 + 6b17587 commit f08b734
Show file tree
Hide file tree
Showing 22 changed files with 894 additions and 597 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.shorthouse.coinwatch.ui.component

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import dev.shorthouse.coinwatch.ui.theme.AppTheme
import org.junit.Rule
Expand All @@ -24,7 +23,6 @@ class ErrorStateTest {
}

composeTestRule.apply {
onNodeWithContentDescription("Error").assertIsDisplayed()
onNodeWithText("An error has occurred").assertIsDisplayed()
}
}
Expand All @@ -40,6 +38,7 @@ class ErrorStateTest {
}

composeTestRule.apply {
onNodeWithText("An error has occurred").assertIsDisplayed()
onNodeWithText("Error message").assertIsDisplayed()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ class MarketScreenTest {
}

composeTestRule.apply {
onNodeWithText("No coins").assertIsDisplayed()
onNodeWithText("Please try again later").assertIsDisplayed()
onNodeWithText("Couldn't load coins").assertIsDisplayed()
onNodeWithText("Check your internet connection").assertIsDisplayed()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SearchScreenTest {
@Test
fun when_uiStateError_should_showErrorMessage() {
val uiState = SearchUiState(
errorMessage = "Error message"
errorMessage = "Unable to fetch coin search results"
)

composeTestRule.setContent {
Expand All @@ -42,7 +42,7 @@ class SearchScreenTest {

composeTestRule.apply {
onNodeWithText("An error has occurred").assertIsDisplayed()
onNodeWithText("Error message").assertIsDisplayed()
onNodeWithText("Unable to fetch coin search results").assertIsDisplayed()
}
}

Expand Down Expand Up @@ -90,6 +90,27 @@ class SearchScreenTest {
}
}

@Test
fun when_searchQueryIsEmpty_should_displayQueryEmptyState() {
val uiState = SearchUiState()

composeTestRule.setContent {
AppTheme {
SearchScreen(
uiState = uiState,
searchQuery = "",
onSearchQueryChange = {},
onCoinClick = {}
)
}
}

composeTestRule.apply {
onNodeWithText("Explore coins").assertIsDisplayed()
onNodeWithText("Search by name or symbol").assertIsDisplayed()
}
}

@Test
fun when_searchQueryEntered_should_displaySearchQuery() {
val searchQuery = "Bitcoin"
Expand Down Expand Up @@ -134,6 +155,28 @@ class SearchScreenTest {
}
}

@Test
fun when_searchQueryEmpty_should_notDisplayClearSearchButton() {
val searchQuery = ""

val uiState = SearchUiState()

composeTestRule.setContent {
AppTheme {
SearchScreen(
uiState = uiState,
searchQuery = searchQuery,
onSearchQueryChange = {},
onCoinClick = {}
)
}
}

composeTestRule.apply {
onNodeWithContentDescription("Clear search").assertDoesNotExist()
}
}

@Test
fun when_clearSearchClicked_should_clearSearchQuery() {
val searchQuery = mutableStateOf("Bitcoin")
Expand Down Expand Up @@ -206,7 +249,7 @@ class SearchScreenTest {
AppTheme {
SearchScreen(
uiState = uiState,
searchQuery = "",
searchQuery = "Bit",
onSearchQueryChange = {},
onCoinClick = {}
)
Expand Down Expand Up @@ -240,7 +283,7 @@ class SearchScreenTest {
AppTheme {
SearchScreen(
uiState = uiState,
searchQuery = "",
searchQuery = "Bit",
onSearchQueryChange = {},
onCoinClick = { onCoinClickCalled = true }
)
Expand Down
Loading

0 comments on commit f08b734

Please sign in to comment.