Skip to content

Commit

Permalink
[#83]
Browse files Browse the repository at this point in the history
- Use coinUiModel instead of coinDetail
- Move HomeScreenUITest to home folder
- Rename DetailScreenUiTest to DetailScreenUITest
  • Loading branch information
kaungkhantsoe committed Feb 21, 2023
1 parent a92cad1 commit dfc863d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import co.nimblehq.compose.crypto.test.TestDispatchersProvider
import co.nimblehq.compose.crypto.ui.components.chartintervals.TimeIntervals
import co.nimblehq.compose.crypto.ui.screens.MainActivity
import co.nimblehq.compose.crypto.ui.screens.detail.*
import co.nimblehq.compose.crypto.ui.screens.home.FIAT_CURRENCY
import co.nimblehq.compose.crypto.ui.uimodel.toUiModel
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -26,7 +26,7 @@ import org.junit.Test
import kotlin.math.abs

@ExperimentalCoroutinesApi
class DetailScreenUiTest {
class DetailScreenUITest {

@get:Rule
val composeAndroidTestRule = createAndroidComposeRule<MainActivity>()
Expand Down Expand Up @@ -56,14 +56,9 @@ class DetailScreenUiTest {
}

@Test
fun when_navigating_to_detail_screen_it_shows_loading() {
fun when_navigating_to_detail_screen__it_shows_loading() {
every { mockGetCoinDetailUseCase.execute(any()) } returns flow {
delay(100L)
emit(coinDetail)
}
every { mockGetCoinPricesUseCase.execute(any()) } returns flow {
delay(100L)
emit(coinPrices)
}

with(composeAndroidTestRule) {
Expand All @@ -72,7 +67,7 @@ class DetailScreenUiTest {
}

@Test
fun when_navigating_to_detail_screen_it_renders_chart_interval_buttons_properly() {
fun when_navigating_to_detail_screen__it_renders_chart_interval_buttons_properly() {
with(composeAndroidTestRule) {
onNodeWithText(TimeIntervals.ONE_DAY.text).assertIsDisplayed()
onNodeWithText(TimeIntervals.ONE_WEEK.text).assertIsDisplayed()
Expand All @@ -83,39 +78,36 @@ class DetailScreenUiTest {
}

@Test
fun when_navigating_to_detail_screen_it_render_currentPrice_and_priceChangePercentage24hInCurrency_properly() {
fun when_navigating_to_detail_screen__it_render_currentPrice_and_priceChangePercentage24hInCurrency_properly() {
with(composeAndroidTestRule) {
coinDetail.marketData?.let { marketData ->
val currentPrice = "$${marketData.currentPrice[FIAT_CURRENCY]?.toFormattedString()}"
onNodeWithText(currentPrice).assertIsDisplayed()

val priceChangePercentage24hInCurrency = this.activity.getString(
R.string.coin_profit_percent,
abs(marketData.priceChangePercentage24hInCurrency[FIAT_CURRENCY] ?: 0.0).toFormattedString()
)
onNodeWithText(priceChangePercentage24hInCurrency).assertIsDisplayed()
}
val coinUiModel = coinDetail.toUiModel()
val currentPrice = "$${coinUiModel.currentPrice.toFormattedString()}"
onNodeWithText(currentPrice).assertIsDisplayed()

val priceChangePercentage24hInCurrency = "${abs(coinUiModel.priceChangePercentage24hInCurrency).toFormattedString()}%"
onNodeWithText(priceChangePercentage24hInCurrency).assertIsDisplayed()
}
}

@Test
fun when_navigating_to_detail_screen_it_render_coin_info_properly() {
fun when_navigating_to_detail_screen__it_render_coin_info_properly() {
with(composeAndroidTestRule) {
coinDetail.marketData?.let { marketData ->
val marketCap = "$${marketData.marketCap[FIAT_CURRENCY]?.toFormattedString()}"
val coinUiModel = coinDetail.toUiModel()
val marketCap = "$${coinUiModel.marketCap.toFormattedString()}"
onNodeWithText(marketCap).assertIsDisplayed()

val allTimeHigh = "$${marketData.ath[FIAT_CURRENCY]?.toFormattedString()}"
onNodeWithText(allTimeHigh).assertIsDisplayed()
val athTimeHigh = "$${coinUiModel.ath.toFormattedString()}"
onNodeWithText(athTimeHigh).assertIsDisplayed()

val allTimeLow = "$${marketData.atl[FIAT_CURRENCY]?.toFormattedString()}"
val allTimeLow = "$${coinUiModel.atl.toFormattedString()}"
onNodeWithText(allTimeLow).assertIsDisplayed()
}
}
}

@Test
fun when_navigating_to_detail_screen_and_has_api_error_coin_price_chart_is_not_displayed() {
fun when_navigating_to_detail_screen_and_has_api_error__coin_price_chart_is_not_displayed() {
every { mockGetCoinDetailUseCase.execute(any()) } returns flow {
throw Throwable(errorGeneric)
}
Expand All @@ -126,7 +118,7 @@ class DetailScreenUiTest {
}

@Test
fun when_navigating_to_detail_screen_chart_interval_buttons_are_clickable() {
fun when_navigating_to_detail_screen__chart_interval_buttons_are_clickable() {
with(composeAndroidTestRule) {
onNodeWithText(TimeIntervals.ONE_DAY.text).assertHasClickAction()
onNodeWithText(TimeIntervals.ONE_WEEK.text).assertHasClickAction()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.nimblehq.compose.crypto.ui.screen
package co.nimblehq.compose.crypto.ui.screen.home

import androidx.activity.compose.setContent
import androidx.compose.ui.test.*
Expand Down

0 comments on commit dfc863d

Please sign in to comment.