Skip to content

Commit

Permalink
[#83] Move data mocking to setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaungkhantsoe committed Feb 21, 2023
1 parent e6763b7 commit b1aa460
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ class DetailScreenUiTest : BaseScreenTest() {

@Before
fun setUp() {
initDetailViewModel()

every { mockGetCoinDetailUseCase.execute(any()) } returns flowOf(coinDetail)
every { mockGetCoinPricesUseCase.execute(any()) } returns flowOf(coinPrices)

initViewModel()
composeAndroidTestRule.activity.setContent {
DetailScreen(
coinId = "",
Expand Down Expand Up @@ -74,8 +78,6 @@ class DetailScreenUiTest : BaseScreenTest() {

@Test
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)

with(composeAndroidTestRule) {
onNodeWithText(TimeIntervals.ONE_DAY.text).assertIsDisplayed()
Expand All @@ -88,8 +90,6 @@ class DetailScreenUiTest : BaseScreenTest() {

@Test
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)

with(composeAndroidTestRule) {
coinDetail.marketData?.let { marketData ->
Expand All @@ -107,8 +107,6 @@ class DetailScreenUiTest : BaseScreenTest() {

@Test
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)

with(composeAndroidTestRule) {
coinDetail.marketData?.let { marketData ->
Expand All @@ -129,7 +127,6 @@ class DetailScreenUiTest : BaseScreenTest() {
every { mockGetCoinDetailUseCase.execute(any()) } returns flow {
throw Throwable(errorGeneric)
}
every { mockGetCoinPricesUseCase.execute(any()) } returns flowOf(coinPrices)

with(composeAndroidTestRule) {
onNodeWithText(TestTagDetailCoinPriceChart).assertDoesNotExist()
Expand All @@ -138,8 +135,6 @@ class DetailScreenUiTest : BaseScreenTest() {

@Test
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)

with(composeAndroidTestRule) {
onNodeWithText(TimeIntervals.ONE_DAY.text).assertHasClickAction()
Expand All @@ -150,7 +145,7 @@ class DetailScreenUiTest : BaseScreenTest() {
}
}

private fun initDetailViewModel() {
private fun initViewModel() {
detailViewModel = DetailViewModel(
dispatchers = testDispatcherProvider,
getCoinDetailUseCase = mockGetCoinDetailUseCase,
Expand Down

0 comments on commit b1aa460

Please sign in to comment.