Skip to content

Commit

Permalink
Merge branch 'navigation-bar' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
shorthouse committed Oct 28, 2023
2 parents 10a591f + 53f20d1 commit 1d57711
Show file tree
Hide file tree
Showing 78 changed files with 2,554 additions and 2,232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,4 @@ class ErrorStateTest {
assertThat(onRetryCalled).isTrue()
}
}

@Test
fun when_navigateUpProvided_should_displayBackButton() {
composeTestRule.setContent {
AppTheme {
ErrorState(
message = null,
onRetry = {},
onNavigateUp = {}
)
}
}

composeTestRule.apply {
onNodeWithContentDescription("Back").assertIsDisplayed().assertHasClickAction()
}
}

@Test
fun when_navigateUpClicked_should_callOnNavigateUp() {
var onNavigateUpCalled = false

composeTestRule.setContent {
AppTheme {
ErrorState(
message = null,
onRetry = {},
onNavigateUp = { onNavigateUpCalled = true }
)
}
}

composeTestRule.apply {
onNodeWithContentDescription("Back").performClick()
assertThat(onNavigateUpCalled).isTrue()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.swipeUp
import com.google.common.truth.Truth.assertThat
import dev.shorthouse.coinwatch.model.CoinChart
import dev.shorthouse.coinwatch.model.CoinDetail
import dev.shorthouse.coinwatch.model.CoinDetails
import dev.shorthouse.coinwatch.model.Percentage
import dev.shorthouse.coinwatch.model.Price
import dev.shorthouse.coinwatch.ui.model.ChartPeriod
import dev.shorthouse.coinwatch.ui.screen.detail.CoinDetailScreen
import dev.shorthouse.coinwatch.ui.screen.detail.CoinDetailUiState
import dev.shorthouse.coinwatch.ui.screen.details.CoinDetailsScreen
import dev.shorthouse.coinwatch.ui.screen.details.DetailsUiState
import dev.shorthouse.coinwatch.ui.theme.AppTheme
import java.math.BigDecimal
import kotlinx.collections.immutable.persistentListOf
import org.junit.Rule
import org.junit.Test

class CoinDetailScreenTest {
class CoinDetailsScreenTest {

@get:Rule
val composeTestRule = createComposeRule()

@Test
fun when_uiStateLoading_should_showSkeletonLoader() {
val uiStateLoading = CoinDetailUiState.Loading
val uiStateLoading = DetailsUiState.Loading

composeTestRule.setContent {
AppTheme {
CoinDetailScreen(
CoinDetailsScreen(
uiState = uiStateLoading,
onNavigateUp = {},
onClickFavouriteCoin = {},
onClickChartPeriod = {},
onErrorRetry = {}
onRefresh = {}
)
}
}
Expand All @@ -54,16 +54,16 @@ class CoinDetailScreenTest {

@Test
fun when_uiStateError_should_showErrorState() {
val uiStateError = CoinDetailUiState.Error("Error message")
val uiStateError = DetailsUiState.Error("Error message")

composeTestRule.setContent {
AppTheme {
CoinDetailScreen(
CoinDetailsScreen(
uiState = uiStateError,
onNavigateUp = {},
onClickFavouriteCoin = {},
onClickChartPeriod = {},
onErrorRetry = {}
onRefresh = {}
)
}
}
Expand All @@ -77,18 +77,18 @@ class CoinDetailScreenTest {
}

@Test
fun when_uiStateErrorRetryClicked_should_callOnErrorRetry() {
var onErrorRetryCalled = false
val uiStateError = CoinDetailUiState.Error("Error message")
fun when_uiStateErrorRetryClicked_should_callOnRefresh() {
var onRefreshCalled = false
val uiStateError = DetailsUiState.Error("Error message")

composeTestRule.setContent {
AppTheme {
CoinDetailScreen(
CoinDetailsScreen(
uiState = uiStateError,
onNavigateUp = {},
onClickFavouriteCoin = {},
onClickChartPeriod = {},
onErrorRetry = { onErrorRetryCalled = true }
onRefresh = { onRefreshCalled = true }
)
}
}
Expand All @@ -97,22 +97,22 @@ class CoinDetailScreenTest {
onNodeWithText("Retry").performClick()
}

assertThat(onErrorRetryCalled).isTrue()
assertThat(onRefreshCalled).isTrue()
}

@Test
fun when_uiStateErrorBackClicked_should_callOnNavigateUp() {
var onNavigateUpCalled = false
val uiStateError = CoinDetailUiState.Error("Error message")
val uiStateError = DetailsUiState.Error("Error message")

composeTestRule.setContent {
AppTheme {
CoinDetailScreen(
CoinDetailsScreen(
uiState = uiStateError,
onNavigateUp = { onNavigateUpCalled = true },
onClickFavouriteCoin = {},
onClickChartPeriod = {},
onErrorRetry = {}
onRefresh = {}
)
}
}
Expand All @@ -126,8 +126,8 @@ class CoinDetailScreenTest {

@Test
fun when_uiStateSuccess_should_showExpectedContent() {
val uiStateSuccess = CoinDetailUiState.Success(
CoinDetail(
val uiStateSuccess = DetailsUiState.Success(
CoinDetails(
id = "ethereum",
name = "Ethereum",
symbol = "ETH",
Expand Down Expand Up @@ -160,12 +160,12 @@ class CoinDetailScreenTest {

composeTestRule.setContent {
AppTheme {
CoinDetailScreen(
CoinDetailsScreen(
uiState = uiStateSuccess,
onNavigateUp = {},
onClickFavouriteCoin = {},
onClickChartPeriod = {},
onErrorRetry = {}
onRefresh = {}
)
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ class CoinDetailScreenTest {
onNodeWithText("High").assertIsDisplayed()
onNodeWithText("$1,922.83").assertIsDisplayed()

onNodeWithTag("coin_detail_content")
onNodeWithTag("coin_details_content")
.performTouchInput { swipeUp(durationMillis = 500) }

onNodeWithText("Market Stats").assertIsDisplayed()
Expand All @@ -219,8 +219,8 @@ class CoinDetailScreenTest {
fun when_backClicked_should_callOnNavigateUp() {
var onNavigateUpCalled = false

val uiStateSuccess = CoinDetailUiState.Success(
CoinDetail(
val uiStateSuccess = DetailsUiState.Success(
CoinDetails(
id = "ethereum",
name = "Ethereum",
symbol = "ETH",
Expand Down Expand Up @@ -253,12 +253,12 @@ class CoinDetailScreenTest {

composeTestRule.setContent {
AppTheme {
CoinDetailScreen(
CoinDetailsScreen(
uiState = uiStateSuccess,
onNavigateUp = { onNavigateUpCalled = true },
onClickFavouriteCoin = {},
onClickChartPeriod = {},
onErrorRetry = {}
onRefresh = {}
)
}
}
Expand All @@ -274,8 +274,8 @@ class CoinDetailScreenTest {
fun when_favouriteCoinClicked_should_callOnClickFavouriteCoin() {
var onClickFavouriteCoinCalled = false

val uiStateSuccess = CoinDetailUiState.Success(
CoinDetail(
val uiStateSuccess = DetailsUiState.Success(
CoinDetails(
id = "ethereum",
name = "Ethereum",
symbol = "ETH",
Expand Down Expand Up @@ -308,12 +308,12 @@ class CoinDetailScreenTest {

composeTestRule.setContent {
AppTheme {
CoinDetailScreen(
CoinDetailsScreen(
uiState = uiStateSuccess,
onNavigateUp = {},
onClickFavouriteCoin = { onClickFavouriteCoinCalled = true },
onClickChartPeriod = {},
onErrorRetry = {}
onRefresh = {}
)
}
}
Expand All @@ -331,8 +331,8 @@ class CoinDetailScreenTest {
.associateWith { false }
.toMutableMap()

val uiStateSuccess = CoinDetailUiState.Success(
CoinDetail(
val uiStateSuccess = DetailsUiState.Success(
CoinDetails(
id = "ethereum",
name = "Ethereum",
symbol = "ETH",
Expand Down Expand Up @@ -365,12 +365,12 @@ class CoinDetailScreenTest {

composeTestRule.setContent {
AppTheme {
CoinDetailScreen(
CoinDetailsScreen(
uiState = uiStateSuccess,
onNavigateUp = {},
onClickFavouriteCoin = {},
onClickChartPeriod = { onClickChartPeriodMap[it] = true },
onErrorRetry = {}
onRefresh = {}
)
}
}
Expand Down
Loading

0 comments on commit 1d57711

Please sign in to comment.