Skip to content

Commit

Permalink
feat: [ANDROAPP-5794] fix ui test and reformat default values
Browse files Browse the repository at this point in the history
  • Loading branch information
xavimolloy committed Feb 23, 2024
1 parent 9644e96 commit 31ae15a
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down Expand Up @@ -190,3 +190,6 @@ private fun formatUIDateToStored(inputDateString: String?, valueType: ValueType?
}
}
}

const val DEFAULT_MIN_DATE = "12111924"
const val DEFAULT_MAX_DATE = "12112124"
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 31ae15a

Please sign in to comment.