From 9ce4ca821261d1c1988502db8fc9307d90019bce Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 4 Jun 2024 15:07:31 +0200 Subject: [PATCH] fix test to change datepicker date --- .../org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt | 10 ++++++++-- .../dhis2/usescases/teidashboard/robot/EventRobot.kt | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt b/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt index 19e4def288..279b92be95 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt @@ -103,7 +103,7 @@ class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { eventRobot(composeTestRule) { clickOnEventDueDate() - selectSpecificDate(getPreviousDate().substring(0, 2)) + selectSpecificDate(getCurrentDatePickerDate(), getPreviousDate()) acceptUpdateEventDate() } } @@ -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) + } } diff --git a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/EventRobot.kt b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/EventRobot.kt index f10138eec9..9f3cdc87f7 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/EventRobot.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/EventRobot.kt @@ -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 @@ -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) {