Skip to content

Commit

Permalink
[#83] Minor function name changes and refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
kaungkhantsoe committed Feb 21, 2023
1 parent eff7052 commit 4c93714
Showing 1 changed file with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.junit.Test
import kotlin.math.abs

@ExperimentalCoroutinesApi
class DetailScreenTest : BaseScreenTest() {
class DetailScreenUiTest : BaseScreenTest() {

@get:Rule
val composeAndroidTestRule = createAndroidComposeRule<MainActivity>()
Expand All @@ -43,6 +43,7 @@ class DetailScreenTest : BaseScreenTest() {

@Before
fun setUp() {
initDetailViewModel()
composeAndroidTestRule.activity.setContent {
DetailScreen(
coinId = "",
Expand All @@ -55,7 +56,7 @@ class DetailScreenTest : BaseScreenTest() {
}

@Test
fun when_navigate_to_detail_screen_it_show_loading() {
fun when_navigating_to_detail_screen_it_shows_loading() {
composeAndroidTestRule.activity.setContent {
DetailScreen(
coinId = "",
Expand All @@ -65,20 +66,16 @@ class DetailScreenTest : BaseScreenTest() {
)
}

initDetailViewModel()

with(composeAndroidTestRule) {
onNodeWithTag(TestTagDetailLoading).assertIsDisplayed()
}
}

@Test
fun when_navigate_to_detail_screen_it_render_chart_interval_buttons_properly() {
fun when_navigating_to_detail_screen_it_renders_chart_interval_buttons_properly() {
every { mockGetCoinDetailUseCase.execute(any()) } returns flowOf(coinDetail)
every { mockGetCoinPricesUseCase.execute(any()) } returns flowOf(coinPrices)

initDetailViewModel()

with(composeAndroidTestRule) {
onNodeWithText(TimeIntervals.ONE_DAY.text).assertIsDisplayed()
onNodeWithText(TimeIntervals.ONE_WEEK.text).assertIsDisplayed()
Expand All @@ -89,12 +86,10 @@ class DetailScreenTest : BaseScreenTest() {
}

@Test
fun when_navigate_to_detail_screen_it_render_currentPrice_and_priceChangePercentage24hInCurrency_properly() {
fun when_navigating_to_detail_screen_it_render_currentPrice_and_priceChangePercentage24hInCurrency_properly() {
every { mockGetCoinDetailUseCase.execute(any()) } returns flowOf(coinDetail)
every { mockGetCoinPricesUseCase.execute(any()) } returns flowOf(coinPrices)

initDetailViewModel()

with(composeAndroidTestRule) {
coinDetail.marketData?.let { marketData ->
val currentPrice = "$${marketData.currentPrice[FIAT_CURRENCY]?.toFormattedString()}"
Expand All @@ -110,12 +105,10 @@ class DetailScreenTest : BaseScreenTest() {
}

@Test
fun when_navigate_to_detail_screen_it_render_coin_info_properly() {
fun when_navigating_to_detail_screen_it_render_coin_info_properly() {
every { mockGetCoinDetailUseCase.execute(any()) } returns flowOf(coinDetail)
every { mockGetCoinPricesUseCase.execute(any()) } returns flowOf(coinPrices)

initDetailViewModel()

with(composeAndroidTestRule) {
coinDetail.marketData?.let { marketData ->
val marketCap = "$${marketData.marketCap[FIAT_CURRENCY]?.toFormattedString()}"
Expand All @@ -131,26 +124,22 @@ class DetailScreenTest : BaseScreenTest() {
}

@Test
fun when_navigate_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)
}
every { mockGetCoinPricesUseCase.execute(any()) } returns flowOf(coinPrices)

initDetailViewModel()

with(composeAndroidTestRule) {
onNodeWithText(TestTagDetailCoinPriceChart).assertDoesNotExist()
}
}

@Test
fun when_navigate_to_detail_screen_chart_interval_buttons_are_clickable() {
fun when_navigating_to_detail_screen_chart_interval_buttons_are_clickable() {
every { mockGetCoinDetailUseCase.execute(any()) } returns flowOf(coinDetail)
every { mockGetCoinPricesUseCase.execute(any()) } returns flowOf(coinPrices)

initDetailViewModel()

with(composeAndroidTestRule) {
onNodeWithText(TimeIntervals.ONE_DAY.text).assertHasClickAction()
onNodeWithText(TimeIntervals.ONE_WEEK.text).assertHasClickAction()
Expand Down

0 comments on commit 4c93714

Please sign in to comment.