Skip to content

Commit

Permalink
Adding HomeScreenRobot
Browse files Browse the repository at this point in the history
  • Loading branch information
philipplackner committed Aug 8, 2023
1 parent 5a73203 commit a136fb9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 21 deletions.
7 changes: 7 additions & 0 deletions app/src/androidTest/java/com/ivy/IvyComposeRule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.ivy

import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.wallet.ui.RootActivity

typealias IvyComposeRule = AndroidComposeTestRule<ActivityScenarioRule<RootActivity>, RootActivity>
73 changes: 73 additions & 0 deletions app/src/androidTest/java/com/ivy/home/HomeScreenRobot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.ivy.home

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.ext.junit.rules.ActivityScenarioRule
import com.ivy.IvyComposeRule
import com.ivy.common.time.provider.TimeProvider
import com.ivy.navigation.Navigator
import com.ivy.navigation.destinations.main.Home
import com.ivy.wallet.ui.RootActivity
import kotlinx.coroutines.runBlocking

class HomeScreenRobot(
private val composeRule: IvyComposeRule
) {
fun navigateTo(navigator: Navigator): HomeScreenRobot {
runBlocking {
composeRule.awaitIdle()
composeRule.runOnUiThread {
navigator.navigate(Home.route) {
popUpTo(Home.route) {
inclusive = false
}
}
}
}
return this
}

fun openDateRangeSheet(timeProvider: TimeProvider): HomeScreenRobot {
composeRule
.onNodeWithText(timeProvider.dateNow().month.name, ignoreCase = true)
.performClick()
return this
}

fun selectMonth(monthName: String): HomeScreenRobot {
composeRule
.onNodeWithText(monthName)
.performClick()
return this
}

fun assertDateIsDisplayed(day: Int, month: String): HomeScreenRobot {
val paddedDay = day.toString().padStart(2, '0')
composeRule
.onNodeWithText("${month.take(3)}. $paddedDay")
.assertIsDisplayed()
return this
}

fun clickDone(): HomeScreenRobot {
composeRule.onNodeWithText("Done").performClick()
return this
}

fun clickUpcoming(): HomeScreenRobot {
composeRule.onNodeWithText("Upcoming").performClick()
return this
}

fun assertTransactionDoesNotExist(transactionTitle: String): HomeScreenRobot {
composeRule.onNodeWithText(transactionTitle).assertDoesNotExist()
return this
}

fun assertTransactionIsDisplayed(transactionTitle: String): HomeScreenRobot {
composeRule.onNodeWithText(transactionTitle).assertIsDisplayed()
return this
}
}
32 changes: 11 additions & 21 deletions app/src/androidTest/java/com/ivy/home/HomeScreenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,17 @@ class HomeScreenTest: IvyAndroidTest() {
transactions = listOf(transaction1, transaction2, transaction3)
)

composeRule.awaitIdle()
composeRule.runOnUiThread {
navigator.navigate(Home.route)
}

composeRule.onNodeWithText(date.month.name, ignoreCase = true).performClick()

composeRule
.onNodeWithText("August")
.assertIsDisplayed()
.performClick()
composeRule.onNodeWithText("Aug. 01").assertIsDisplayed()
composeRule.onNodeWithText("Aug. 31").assertIsDisplayed()

composeRule.onNodeWithText("Done").performClick()

composeRule.onNodeWithText("Upcoming").performClick()

composeRule.onNodeWithText("Transaction1").assertDoesNotExist()
composeRule.onNodeWithText("Transaction2").assertIsDisplayed()
composeRule.onNodeWithText("Transaction3").assertIsDisplayed()
HomeScreenRobot(composeRule)
.navigateTo(navigator)
.openDateRangeSheet(timeProvider)
.selectMonth("August")
.assertDateIsDisplayed(1, "August")
.assertDateIsDisplayed(31, "August")
.clickDone()
.clickUpcoming()
.assertTransactionDoesNotExist("Transaction1")
.assertTransactionIsDisplayed("Transaction2")
.assertTransactionIsDisplayed("Transaction3")
}

}

0 comments on commit a136fb9

Please sign in to comment.