Skip to content

Commit

Permalink
fix test to change datepicker date
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos committed Jun 4, 2024
1 parent a318875 commit c08e03a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {

eventRobot(composeTestRule) {
clickOnEventDueDate()
selectSpecificDate(getPreviousDate().substring(0, 2))
selectSpecificDate(getCurrentDatePickerDate(), getPreviousDate())
acceptUpdateEventDate()
}
}
Expand All @@ -115,9 +115,15 @@ class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
}

private fun getPreviousDate(): String {
val sdf = SimpleDateFormat("ddMMYYYY")
val sdf = SimpleDateFormat("MMddYYYY")
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_MONTH, -1)
return sdf.format(calendar.time)
}

private fun getCurrentDatePickerDate(): String {
val sdf = SimpleDateFormat("MM/dd/YYYY")
val calendar = Calendar.getInstance()
return sdf.format(calendar.time)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.test.hasAnySibling
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
Expand Down Expand Up @@ -110,9 +111,13 @@ class EventRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {

}

fun selectSpecificDate(date: String) {
fun selectSpecificDate(currentDate: String, date: String) {
composeTestRule.onNodeWithTag("DATE_PICKER").assertIsDisplayed()
composeTestRule.onNode(hasText(date, true)).performClick()
composeTestRule.onNodeWithContentDescription(
"Switch to text input mode",
useUnmergedTree = true,
).performClick()
composeTestRule.onNodeWithText(currentDate).performTextReplacement(date)
}

fun typeOnDateParameter(dateValue: String) {
Expand Down

0 comments on commit c08e03a

Please sign in to comment.