From 31ae15af72d046cb960a190993e2408716dd30dd Mon Sep 17 00:00:00 2001 From: Xavier Molloy Date: Fri, 23 Feb 2024 09:39:28 +0100 Subject: [PATCH] feat: [ANDROAPP-5794] fix ui test and reformat default values --- .../usescases/flow/teiFlow/TeiFlowRobot.kt | 14 +++------ .../usescases/flow/teiFlow/TeiFlowTest.kt | 2 ++ .../dhis2/usescases/searchte/SearchTETest.kt | 12 ++++--- .../teidashboard/robot/EventRobot.kt | 31 ++++++++++--------- .../events/ScheduledEventPresenterImpl.kt | 6 ++-- .../providers/InputFieldsProvider.kt | 2 ++ .../eventDetails/ui/EventDetailsViewModel.kt | 6 ++-- .../ui/provider/inputfield/DateProvider.kt | 7 +++-- gradle/libs.versions.toml | 2 +- 9 files changed, 47 insertions(+), 35 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 79c3515157..e7d1f9b563 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 @@ -4,6 +4,7 @@ import androidx.compose.ui.test.junit4.ComposeContentTestRule import androidx.compose.ui.test.junit4.ComposeTestRule import org.dhis2.common.BaseRobot import org.dhis2.usescases.flow.teiFlow.entity.DateRegistrationUIModel +import org.dhis2.usescases.searchte.robot.searchTeiRobot import org.dhis2.usescases.flow.teiFlow.entity.EnrollmentListUIModel import org.dhis2.usescases.flow.teiFlow.entity.RegisterTEIUIModel import org.dhis2.usescases.searchte.robot.searchTeiRobot @@ -100,21 +101,16 @@ class TeiFlowRobot : BaseRobot() { } } - fun changeDueDate( - date: DateRegistrationUIModel, - programStage: String, - orgUnit: String, - composeTestRule: ComposeTestRule - ) { + fun changeDueDate(date: String, programStage: String, orgUnit: String, composeTestRule: ComposeTestRule) { teiDashboardRobot { clickOnStageGroup(programStage) clickOnEventGroupByStageUsingOU(orgUnit) } eventRobot { - clickOnEventDueDate(composeTestRule) - selectSpecificDate(date.year, date.month, date.day) - acceptUpdateEventDate() + clickOnEventReportDate(composeTestRule) + selectSpecificDate(composeTestRule, date) + acceptUpdateEventDate(composeTestRule) } } } 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 83ec08eb93..1aed972061 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 @@ -105,5 +105,7 @@ class TeiFlowTest: BaseTest() { const val LASTNAME = "Stuart" const val DATE_FORMAT = "dd/M/yyyy" + const val DATE_PICKER_FORMAT = "EEEE, MMMM d, yyyy" + } } \ 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 7be06c8d2d..b62e5c2fbc 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/searchte/SearchTETest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/searchte/SearchTETest.kt @@ -35,6 +35,7 @@ import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import java.text.SimpleDateFormat +import java.util.Calendar import java.util.Date @RunWith(AndroidJUnit4::class) @@ -432,11 +433,12 @@ class SearchTETest : BaseTest() { return DateRegistrationUIModel(year, month, day) } - private fun createOverdueDate() = DateRegistrationUIModel( - currentDate.year, - currentDate.month - 1, - currentDate.day - ) + private fun createOverdueDate() : String { + val sdf = SimpleDateFormat(TeiFlowTest.DATE_PICKER_FORMAT) + val calendar = Calendar.getInstance() + calendar.add(Calendar.DAY_OF_YEAR, -7) + return sdf.format(calendar.time) + } private val dateRegistration = createFirstSpecificDate() private val dateEnrollment = createEnrollmentDate() 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 625f39c53a..c9bff4aa46 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 @@ -1,14 +1,17 @@ package org.dhis2.usescases.teidashboard.robot import androidx.compose.ui.test.assertIsDisplayed +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.onNodeWithText import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.printToLog 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.actionOnItemAtPosition import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withSubstring @@ -80,8 +83,8 @@ class EventRobot : BaseRobot() { onView(withId(R.id.date)).perform(click()) } - fun acceptUpdateEventDate() { - onView(withId(R.id.acceptBtn)).perform(click()) + fun acceptUpdateEventDate(composeTestRule: ComposeTestRule) { + composeTestRule.onNodeWithText("OK",true).performClick() } fun clickOnUpdate() { @@ -97,12 +100,6 @@ class EventRobot : BaseRobot() { ) } - fun clickOnFutureAlertDialog(){ - clickOnChangeDate() - clickOnEditDate() - acceptUpdateEventDate() - clickOnUpdate() - } fun checkDetails(eventDate: String, eventOrgUnit: String) { onView(withId(R.id.eventSecundaryInfo)).check(matches( @@ -133,14 +130,20 @@ class EventRobot : BaseRobot() { onView(withId(R.id.possitive)).perform(click()) } - fun clickOnEventDueDate(composeTestRule: ComposeTestRule) { - composeTestRule.onNodeWithTag("INPUT_DATE_TIME_TEXT").assertIsDisplayed() - composeTestRule.onNodeWithTag("INPUT_DATE_TIME_TEXT").performClick() + fun clickOnEventReportDate(composeTestRule: ComposeTestRule) { + + composeTestRule.onNode(hasTestTag("INPUT_DATE_TIME_ACTION_BUTTON") and hasAnySibling( + hasText("Report date") + )).assertIsDisplayed().performClick() } - fun selectSpecificDate(year: Int, monthOfYear: Int, dayOfMonth: Int) { - onView(withId(R.id.datePicker)).perform(PickerActions.setDate(year, monthOfYear, dayOfMonth)) + fun selectSpecificDate( composeTestRule: ComposeTestRule, date: String) { + composeTestRule.onNodeWithTag("DATE_PICKER").assertIsDisplayed().printToLog("DATE-PICKER-COMPONENTS") + + composeTestRule.onNodeWithText(date,true).performClick() + composeTestRule.onNodeWithTag("DATE_PICKER").printToLog("DATE-PICKER2") + } fun checkEventDetails(eventDate: String, eventOrgUnit: String, composeTestRule: ComposeTestRule) { diff --git a/app/src/main/java/org/dhis2/usescases/events/ScheduledEventPresenterImpl.kt b/app/src/main/java/org/dhis2/usescases/events/ScheduledEventPresenterImpl.kt index af6d0612bf..0815cde501 100644 --- a/app/src/main/java/org/dhis2/usescases/events/ScheduledEventPresenterImpl.kt +++ b/app/src/main/java/org/dhis2/usescases/events/ScheduledEventPresenterImpl.kt @@ -4,6 +4,8 @@ import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import org.dhis2.data.dhislogic.DhisEventUtils +import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.providers.DEFAULT_MAX_DATE +import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.providers.DEFAULT_MIN_DATE import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.providers.InputDateValues import org.dhis2.utils.DateUtils import org.hisp.dhis.android.core.D2 @@ -111,8 +113,8 @@ class ScheduledEventPresenterImpl( null } val minDateString = if (minDate == null) null else SimpleDateFormat("ddMMyyyy", Locale.US).format(minDate) - val maxDateString = if (isDueDate)"12112124" else SimpleDateFormat("ddMMyyyy", Locale.US).format(Date(System.currentTimeMillis() - 1000)) - return SelectableDates(minDateString ?: "12111924", maxDateString) + val maxDateString = if (isDueDate) DEFAULT_MAX_DATE else SimpleDateFormat("ddMMyyyy", Locale.US).format(Date(System.currentTimeMillis() - 1000)) + return SelectableDates(minDateString ?: DEFAULT_MIN_DATE, maxDateString) } override fun setDueDate(date: Date) { diff --git a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/providers/InputFieldsProvider.kt b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/providers/InputFieldsProvider.kt index ce62c5fe1e..eeee49f23c 100644 --- a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/providers/InputFieldsProvider.kt +++ b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/providers/InputFieldsProvider.kt @@ -442,3 +442,5 @@ fun ProvideRadioButtons( const val INPUT_EVENT_INITIAL_DATE = "INPUT_EVENT_INITIAL_DATE" const val EMPTY_CATEGORY_SELECTOR = "EMPTY_CATEGORY_SELECTOR" const val CATEGORY_SELECTOR = "CATEGORY_SELECTOR" +const val DEFAULT_MIN_DATE = "12111924" +const val DEFAULT_MAX_DATE = "12112124" diff --git a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailsViewModel.kt b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailsViewModel.kt index 09bcf7a242..93bdcd261e 100644 --- a/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailsViewModel.kt +++ b/app/src/main/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/ui/EventDetailsViewModel.kt @@ -24,6 +24,8 @@ import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.models.EventDe import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.models.EventOrgUnit import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.models.EventTemp import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.models.EventTempStatus +import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.providers.DEFAULT_MAX_DATE +import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.providers.DEFAULT_MIN_DATE import org.dhis2.usescases.eventsWithoutRegistration.eventDetails.providers.EventDetailResourcesProvider import org.hisp.dhis.android.core.arch.helpers.GeometryHelper import org.hisp.dhis.android.core.common.FeatureType @@ -247,10 +249,10 @@ class EventDetailsViewModel( fun getSelectableDates(eventDate: EventDate): SelectableDates { return if (eventDate.allowFutureDates) { - SelectableDates("12111924", "12112124") + SelectableDates(DEFAULT_MIN_DATE, DEFAULT_MAX_DATE) } else { val currentDate = SimpleDateFormat("ddMMyyyy", Locale.US).format(Date(System.currentTimeMillis())) - SelectableDates("12111924", currentDate) + SelectableDates(DEFAULT_MIN_DATE, currentDate) } } diff --git a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/DateProvider.kt b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/DateProvider.kt index a866cee6de..e4f4d50d6a 100644 --- a/form/src/main/java/org/dhis2/form/ui/provider/inputfield/DateProvider.kt +++ b/form/src/main/java/org/dhis2/form/ui/provider/inputfield/DateProvider.kt @@ -55,10 +55,10 @@ fun ProvideInputDate( } val yearIntRange = if (fieldUiModel.allowFutureDates == true) IntRange(1924, 2124) else (IntRange(1924, Calendar.getInstance().get(Calendar.YEAR))) val selectableDates = if (fieldUiModel.allowFutureDates == true) { - SelectableDates(initialDate = "12111924", endDate = "12112124") + SelectableDates(initialDate = DEFAULT_MIN_DATE, endDate = DEFAULT_MAX_DATE) } else { SelectableDates( - initialDate = "12111924", + initialDate = DEFAULT_MIN_DATE, endDate = SimpleDateFormat("ddMMyyyy", Locale.US).format( Date(System.currentTimeMillis() - 1000), ), @@ -190,3 +190,6 @@ private fun formatUIDateToStored(inputDateString: String?, valueType: ValueType? } } } + +const val DEFAULT_MIN_DATE = "12111924" +const val DEFAULT_MAX_DATE = "12112124" diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9cb7c3a0e8..43b5d1265c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ kotlin = '1.9.21' hilt = '2.47' hiltCompiler = '1.0.0' jacoco = '0.8.10' -designSystem = "0.2-20240220.152822-29" +designSystem = "0.2-20240222.160714-31" dhis2sdk = "1.10.0-20240207.110936-11" ruleEngine = "2.1.9" appcompat = "1.6.1"