Skip to content

Commit

Permalink
test: [ANDROAPP-5987] shouldSuccessfullyFilterByEventStatusOverdue
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos committed May 28, 2024
1 parent c35f6dd commit 55721ec
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SearchFlowTest : BaseTest() {
)
val filterCounter = "1"
val filterTotalCount = "2"
enableComposeForms()
prepareWomanProgrammeIntentAndLaunchActivity(rule)

teiFlowRobot(composeTestRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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()
}
}
Expand All @@ -53,10 +51,9 @@ class TeiFlowRobot(val composeTestRule: ComposeTestRule) : BaseRobot() {
clickOnMenuProgramEnrollments()
}

enrollmentRobot {
enrollmentRobot(composeTestRule) {
clickOnAProgramForEnrollment(composeTestRule, program)
clickOnAcceptInDatePicker()
scrollToBottomProgramForm()
clickOnSaveEnrollment()
}
}
Expand All @@ -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)
}

Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TeiFlowTest : BaseTest() {
val enrollmentListDetails = createEnrollmentList()
val registerTeiDetails = createRegisterTEI()

enableComposeForms()
setupCredentials()
setDatePicker()
prepareWomanProgrammeIntentAndLaunchActivity(ruleSearch)
Expand Down Expand Up @@ -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"

}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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),
)
}
}
Expand Down Expand Up @@ -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),
)
}
}
Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -192,9 +185,7 @@ class SearchTETest : BaseTest() {

teiFlowRobot(composeTestRule) {
registerTEI(registerTeiDetails)
changeDueDate(scheduledEventTitle, overdueDate)
pressBack()
composeTestRule.onNodeWithTag(SECONDARY_BUTTON_TAG).performClick()
changeDueDate(scheduledEventTitle)
pressBack()
}

Expand All @@ -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")
}
}

Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class TeiDashboardTest : BaseTest() {
clickOnMenuProgramEnrollments()
}

enrollmentRobot {
enrollmentRobot(composeTestRule) {
clickOnAProgramForEnrollment(composeTestRule, womanProgram)
clickOnAcceptInDatePicker()
clickOnPersonAttributes(personAttribute)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -123,23 +129,13 @@ class EnrollmentRobot : BaseRobot() {
)
}

fun clickOnInputDate(label: String) {
onView(withId(R.id.recyclerView))
.perform(
actionOnItem<FormViewHolder>(
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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)
}
}

Expand Down

0 comments on commit 55721ec

Please sign in to comment.