From 194bfcde2c3ac6eb6eeba2ce96c2e06503848dda Mon Sep 17 00:00:00 2001 From: manu Date: Fri, 24 May 2024 10:58:17 +0200 Subject: [PATCH] test: [ANDROAPP-5987] shouldSuccessfullyFilterByEventStatusOverdue --- .../flow/searchFlow/SearchFlowTest.kt | 1 + .../usescases/flow/teiFlow/TeiFlowRobot.kt | 43 +++++++++++-------- .../usescases/flow/teiFlow/TeiFlowTest.kt | 3 +- .../dhis2/usescases/searchte/SearchTETest.kt | 30 ++++--------- .../searchte/robot/SearchTeiRobot.kt | 9 ++++ .../teidashboard/TeiDashboardTest.kt | 2 +- .../teidashboard/robot/EnrollmentRobot.kt | 38 ++++++++-------- .../teidashboard/robot/EventRobot.kt | 8 ++-- 8 files changed, 67 insertions(+), 67 deletions(-) diff --git a/app/src/androidTest/java/org/dhis2/usescases/flow/searchFlow/SearchFlowTest.kt b/app/src/androidTest/java/org/dhis2/usescases/flow/searchFlow/SearchFlowTest.kt index 2807eded53..5b7feb4bbc 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/flow/searchFlow/SearchFlowTest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/flow/searchFlow/SearchFlowTest.kt @@ -39,6 +39,7 @@ class SearchFlowTest : BaseTest() { ) val filterCounter = "1" val filterTotalCount = "2" + enableComposeForms() prepareWomanProgrammeIntentAndLaunchActivity(rule) teiFlowRobot(composeTestRule) { 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 ad45d83a45..19e4def288 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 @@ -8,10 +8,12 @@ import org.dhis2.usescases.searchte.robot.searchTeiRobot import org.dhis2.usescases.teidashboard.robot.enrollmentRobot import org.dhis2.usescases.teidashboard.robot.eventRobot import org.dhis2.usescases.teidashboard.robot.teiDashboardRobot +import java.text.SimpleDateFormat +import java.util.Calendar fun teiFlowRobot( composeTestRule: ComposeTestRule, - teiFlowRobot: TeiFlowRobot.() -> Unit + teiFlowRobot: TeiFlowRobot.() -> Unit, ) { TeiFlowRobot(composeTestRule).apply { teiFlowRobot() @@ -21,10 +23,10 @@ fun teiFlowRobot( class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { fun registerTEI( - registrationModel: RegisterTEIUIModel + registrationModel: RegisterTEIUIModel, ) { val registrationDate = registrationModel.firstSpecificDate - val enrollmentDate = registrationModel.enrollmentDate + val incidentDate = getCurrentDate() searchTeiRobot(composeTestRule) { openNextSearchParameter("First name") @@ -37,12 +39,8 @@ class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { clickOnEnroll() } - enrollmentRobot { - clickOnInputDate("Date of enrollment *") - selectSpecificDate(enrollmentDate.year, enrollmentDate.month, enrollmentDate.day) - clickOnAcceptInDatePicker() - clickOnInputDate("LMP Date *") - clickOnAcceptInDatePicker() + enrollmentRobot(composeTestRule) { + typeOnDateParameterWithLabel("LMP Date *", incidentDate) clickOnSaveEnrollment() } } @@ -53,10 +51,9 @@ class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { clickOnMenuProgramEnrollments() } - enrollmentRobot { + enrollmentRobot(composeTestRule) { clickOnAProgramForEnrollment(composeTestRule, program) clickOnAcceptInDatePicker() - scrollToBottomProgramForm() clickOnSaveEnrollment() } } @@ -67,16 +64,16 @@ class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { clickOnMenuProgramEnrollments() } - enrollmentRobot { + enrollmentRobot(composeTestRule) { waitToDebounce(1000) checkActiveAndPastEnrollmentDetails(enrollmentDetails) } } fun checkPastEventsAreClosed( - programPosition: Int + programPosition: Int, ) { - enrollmentRobot { + enrollmentRobot(composeTestRule) { clickOnEnrolledProgram(programPosition) } @@ -99,16 +96,28 @@ class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { fun changeDueDate( cardTitle: String, - date: String, ) { teiDashboardRobot(composeTestRule) { clickOnEventGroupByStageUsingDate(cardTitle) } eventRobot(composeTestRule) { - clickOnEventReportDate() - selectSpecificDate(date) + clickOnEventDueDate() + selectSpecificDate(getPreviousDate().substring(0, 2)) acceptUpdateEventDate() } } + + private fun getCurrentDate(): String { + val sdf = SimpleDateFormat("ddMMYYYY") + val calendar = Calendar.getInstance() + return sdf.format(calendar.time) + } + + private fun getPreviousDate(): String { + val sdf = SimpleDateFormat("ddMMYYYY") + val calendar = Calendar.getInstance() + calendar.add(Calendar.DAY_OF_MONTH, -1) + return sdf.format(calendar.time) + } } diff --git a/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowTest.kt b/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowTest.kt index 5b8cf533e8..6b29f3bc30 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowTest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowTest.kt @@ -39,6 +39,7 @@ class TeiFlowTest : BaseTest() { val enrollmentListDetails = createEnrollmentList() val registerTeiDetails = createRegisterTEI() + enableComposeForms() setupCredentials() setDatePicker() prepareWomanProgrammeIntentAndLaunchActivity(ruleSearch) @@ -104,7 +105,5 @@ class TeiFlowTest : BaseTest() { const val LASTNAME = "Stuart" const val DATE_FORMAT = "dd/M/yyyy" - const val DATE_PICKER_FORMAT = ", d MMMM" - } } \ No newline at end of file diff --git a/app/src/androidTest/java/org/dhis2/usescases/searchte/SearchTETest.kt b/app/src/androidTest/java/org/dhis2/usescases/searchte/SearchTETest.kt index eadaad1c7b..3472dbc780 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/searchte/SearchTETest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/searchte/SearchTETest.kt @@ -1,10 +1,6 @@ package org.dhis2.usescases.searchte -import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.createComposeRule -import androidx.compose.ui.test.onNodeWithTag -import androidx.compose.ui.test.onNodeWithText -import androidx.compose.ui.test.performClick import androidx.compose.ui.text.capitalize import androidx.compose.ui.text.intl.Locale import androidx.test.espresso.IdlingRegistry @@ -21,9 +17,7 @@ import org.dhis2.bindings.app import org.dhis2.common.idlingresources.MapIdlingResource import org.dhis2.commons.date.DateUtils.SIMPLE_DATE_FORMAT import org.dhis2.lazyActivityScenarioRule -import org.dhis2.ui.dialogs.bottomsheet.SECONDARY_BUTTON_TAG import org.dhis2.usescases.BaseTest -import org.dhis2.usescases.flow.teiFlow.TeiFlowTest import org.dhis2.usescases.flow.teiFlow.entity.DateRegistrationUIModel import org.dhis2.usescases.flow.teiFlow.entity.RegisterTEIUIModel import org.dhis2.usescases.flow.teiFlow.teiFlowRobot @@ -75,7 +69,7 @@ class SearchTETest : BaseTest() { clickOnSearch() checkListOfSearchTEI( title = "First name: $firstName", - attributes = mapOf("Last name:" to lastName) + attributes = mapOf("Last name:" to lastName), ) } } @@ -112,7 +106,7 @@ class SearchTETest : BaseTest() { composeTestRule.waitForIdle() checkListOfSearchTEI( title = "First name: $firstName", - attributes = mapOf("Last name:" to lastName) + attributes = mapOf("Last name:" to lastName), ) } } @@ -156,7 +150,7 @@ class SearchTETest : BaseTest() { val enrollmentStatusFilter = context.getString(R.string.filters_title_enrollment_status) .format( context.resources.getQuantityString(R.plurals.enrollment, 1) - .capitalize(Locale.current) + .capitalize(Locale.current), ) val totalFilterCount = "2" val filterCount = "1" @@ -176,12 +170,11 @@ class SearchTETest : BaseTest() { } @Test - @Ignore("Test is successful locally but not in browserstack") fun shouldSuccessfullyFilterByEventStatusOverdue() { + enableComposeForms() val eventStatusFilter = context.getString(R.string.filters_title_event_status) val totalCount = "1" val registerTeiDetails = createRegisterTEI() - val overdueDate = getCurrentDate() val dateFormat = SimpleDateFormat(SIMPLE_DATE_FORMAT, java.util.Locale.getDefault()).format(Date()) val scheduledEventTitle = context.getString(R.string.scheduled_for) @@ -192,9 +185,7 @@ class SearchTETest : BaseTest() { teiFlowRobot(composeTestRule) { registerTEI(registerTeiDetails) - changeDueDate(scheduledEventTitle, overdueDate) - pressBack() - composeTestRule.onNodeWithTag(SECONDARY_BUTTON_TAG).performClick() + changeDueDate(scheduledEventTitle) pressBack() } @@ -205,8 +196,9 @@ class SearchTETest : BaseTest() { closeFilterRowAtField(eventStatusFilter) checkFilterCounter(totalCount) checkCountAtFilter(eventStatusFilter, totalCount) - clickOnFilter() - checkEventsAreOverdue() + } + searchTeiRobot(composeTestRule) { + checkListOfSearchTEIWithAdditionalInfo("First name: ADRIANNA", "1 day overdue") } } @@ -437,12 +429,6 @@ class SearchTETest : BaseTest() { 30 ) - private fun getCurrentDate(): String { - val sdf = SimpleDateFormat(TeiFlowTest.DATE_PICKER_FORMAT) - val calendar = Calendar.getInstance() - return sdf.format(calendar.time) - } - private val dateRegistration = createFirstSpecificDate() private val dateEnrollment = createEnrollmentDate() diff --git a/app/src/androidTest/java/org/dhis2/usescases/searchte/robot/SearchTeiRobot.kt b/app/src/androidTest/java/org/dhis2/usescases/searchte/robot/SearchTeiRobot.kt index 8080cc13a7..9e27f720e5 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/searchte/robot/SearchTeiRobot.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/searchte/robot/SearchTeiRobot.kt @@ -204,6 +204,15 @@ class SearchTeiRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { onView(withId(R.id.createButton)).perform(click()) } + fun checkListOfSearchTEIWithAdditionalInfo(title: String, additionalText: String) { + composeTestRule.onNodeWithText(title).assertIsDisplayed() + composeTestRule.onNode( + hasParent(hasTestTag("LIST_CARD_ADDITIONAL_INFO_COLUMN")) + and hasText(additionalText), + useUnmergedTree = true, + ).assertIsDisplayed() + } + private fun createAttributesList(displayListFieldsUIModel: DisplayListFieldsUIModel) = listOf( AdditionalInfoItem( key = "Last name:", diff --git a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/TeiDashboardTest.kt b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/TeiDashboardTest.kt index b6dc9db96f..072d9f7798 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/TeiDashboardTest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/TeiDashboardTest.kt @@ -271,7 +271,7 @@ class TeiDashboardTest : BaseTest() { clickOnMenuProgramEnrollments() } - enrollmentRobot { + enrollmentRobot(composeTestRule) { clickOnAProgramForEnrollment(composeTestRule, womanProgram) clickOnAcceptInDatePicker() clickOnPersonAttributes(personAttribute) diff --git a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/EnrollmentRobot.kt b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/EnrollmentRobot.kt index 12eef6b090..3451bb75d9 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/EnrollmentRobot.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/EnrollmentRobot.kt @@ -1,12 +1,15 @@ package org.dhis2.usescases.teidashboard.robot +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.onNodeWithTag import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performTextReplacement import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches -import androidx.test.espresso.contrib.PickerActions import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition import androidx.test.espresso.matcher.ViewMatchers.hasDescendant @@ -24,13 +27,16 @@ import org.dhis2.usescases.teiDashboard.teiProgramList.ui.PROGRAM_TO_ENROLL import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.containsString -fun enrollmentRobot(enrollmentRobot: EnrollmentRobot.() -> Unit) { - EnrollmentRobot().apply { +fun enrollmentRobot( + composeTestRule: ComposeTestRule, + enrollmentRobot: EnrollmentRobot.() -> Unit, +) { + EnrollmentRobot(composeTestRule).apply { enrollmentRobot() } } -class EnrollmentRobot : BaseRobot() { +class EnrollmentRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { fun clickOnAProgramForEnrollment(composeTestRule: ComposeTestRule, program: String) { composeTestRule.onNodeWithTag(PROGRAM_TO_ENROLL.format(program), useUnmergedTree = true) @@ -123,23 +129,13 @@ class EnrollmentRobot : BaseRobot() { ) } - fun clickOnInputDate(label: String) { - onView(withId(R.id.recyclerView)) - .perform( - actionOnItem( - hasDescendant(withText(label)), clickChildViewWithId(R.id.inputEditText) - ) - ) - } - - fun selectSpecificDate(year: Int, monthOfYear: Int, dayOfMonth: Int) { - onView(withId(R.id.datePicker)).perform( - PickerActions.setDate( - year, - monthOfYear, - dayOfMonth - ) - ) + fun typeOnDateParameterWithLabel(label: String, dateValue: String) { + composeTestRule.apply { + onNode( + hasTestTag("INPUT_DATE_TIME_TEXT_FIELD") and hasAnySibling(hasText(label)), + useUnmergedTree = true, + ).performTextReplacement(dateValue) + } } companion object { 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 e3413e3983..f10138eec9 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 @@ -8,7 +8,7 @@ import androidx.compose.ui.test.junit4.ComposeTestRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick -import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.test.performTextReplacement import androidx.test.espresso.Espresso.onView import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.assertion.ViewAssertions.matches @@ -101,10 +101,10 @@ class EventRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { onView(withId(R.id.possitive)).perform(click()) } - fun clickOnEventReportDate() { + fun clickOnEventDueDate() { composeTestRule.onNode( hasTestTag("INPUT_DATE_TIME_ACTION_BUTTON") and hasAnySibling( - hasText("Report date") + hasText("Due date") ) ).assertIsDisplayed().performClick() @@ -118,7 +118,7 @@ class EventRobot(val composeTestRule: ComposeTestRule) : BaseRobot() { fun typeOnDateParameter(dateValue: String) { composeTestRule.apply { onNodeWithTag("INPUT_DATE_TIME_TEXT_FIELD").performClick() - onNodeWithTag("INPUT_DATE_TIME_TEXT_FIELD").performTextInput(dateValue) + onNodeWithTag("INPUT_DATE_TIME_TEXT_FIELD").performTextReplacement(dateValue) } }