Skip to content

Commit

Permalink
Merge pull request #3497 from dhis2/ANDROAPP-5800-Search-page
Browse files Browse the repository at this point in the history
[ANDROAPP-5800] Search parameters
  • Loading branch information
andresmr authored Feb 23, 2024
2 parents 1260a1f + 4c4730a commit a0899a5
Show file tree
Hide file tree
Showing 68 changed files with 1,297 additions and 1,222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.dhis2.usescases.flow.searchFlow

import org.dhis2.common.BaseRobot
import org.dhis2.usescases.searchte.robot.filterRobot
import org.dhis2.usescases.searchte.robot.searchTeiRobot

fun searchFlowRobot(searchFlowRobot: SearchFlowRobot.() -> Unit) {
SearchFlowRobot().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.dhis2.usescases.flow.searchFlow
import android.content.Intent
import androidx.compose.ui.text.capitalize
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import org.dhis2.R
Expand All @@ -21,6 +22,9 @@ class SearchFlowTest : BaseTest() {
@get:Rule
val rule = ActivityTestRule(SearchTEActivity::class.java, false, false)

@get:Rule
val composeTestRule = createComposeRule()

private val dateRegistration = createFirstSpecificDate()
private val dateEnrollment = createEnrollmentDate()

Expand All @@ -35,7 +39,7 @@ class SearchFlowTest : BaseTest() {
prepareWomanProgrammeIntentAndLaunchActivity(rule)

teiFlowRobot {
registerTEI(registerTEIDetails)
registerTEI(registerTEIDetails, composeTestRule)
pressBack()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ class SyncFlowTest : BaseTest() {

prepareTBProgrammeIntentAndLaunchActivity(ruleSearch)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnOpenSearch()
typeAttributeAtPosition(teiName, 0)
typeAttributeAtPosition(teiLastName, 1)
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(teiName)
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(teiLastName)
clickOnSearch()
clickOnTEI(teiName, teiLastName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ fun teiFlowRobot(teiFlowRobot: TeiFlowRobot.() -> Unit) {

class TeiFlowRobot : BaseRobot() {

fun registerTEI(registrationModel: RegisterTEIUIModel) {
fun registerTEI(
registrationModel: RegisterTEIUIModel,
composeTestRule: ComposeContentTestRule
) {
val registrationDate = registrationModel.firstSpecificDate
val enrollmentDate = registrationModel.enrollmentDate

searchTeiRobot {
typeAttributeAtPosition(registrationModel.name, 0)
typeAttributeAtPosition(registrationModel.lastName, 1)
clickOnDateField()
selectSpecificDate(registrationDate.year, registrationDate.month, registrationDate.day)
acceptDate()
searchTeiRobot(composeTestRule) {
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(registrationModel.name)
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(registrationModel.lastName)
openNextSearchParameter("Date of birth")
typeOnDateParameter("${registrationDate.day}0${registrationDate.month}${registrationDate.year}")
clickOnSearch()
clickOnEnroll()
selectSpecificDate(enrollmentDate.year, enrollmentDate.month, enrollmentDate.day)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TeiFlowTest: BaseTest() {
prepareWomanProgrammeIntentAndLaunchActivity(ruleSearch)

teiFlowRobot {
registerTEI(registerTeiDetails)
registerTEI(registerTeiDetails, composeTestRule)
closeEnrollmentAndCheckEvents(composeTestRule,totalEventsPerEnrollment)
enrollToProgram(composeTestRule, ADULT_WOMAN_PROGRAM)
checkActiveAndPastEnrollmentDetails(enrollmentListDetails)
Expand Down
8 changes: 4 additions & 4 deletions app/src/androidTest/java/org/dhis2/usescases/form/FormTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.dhis2.usescases.searchte.robot.searchTeiRobot
import org.dhis2.usescases.teiDashboard.TeiDashboardMobileActivity
import org.dhis2.usescases.teidashboard.robot.enrollmentRobot
import org.dhis2.usescases.teidashboard.robot.eventRobot
import org.dhis2.usescases.teidashboard.robot.teiDashboardRobot
import org.junit.After
import org.junit.Ignore
import org.junit.Rule
Expand Down Expand Up @@ -241,7 +240,7 @@ class FormTest : BaseTest() {
val firstSectionPosition = 1
startSearchActivity(ruleSearch)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnOpenSearch()
typeAttributeAtPosition("optionGroup", 1)
clickOnSearch()
Expand Down Expand Up @@ -285,9 +284,10 @@ class FormTest : BaseTest() {

startSearchActivity(ruleSearch)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnOpenSearch()
typeAttributeAtPosition("abc", 1)
openNextSearchParameter("First name")
typeOnNextSearchTextParameter("abc")
clickOnSearch()
clickOnEnroll()
orgUnitSelectorRobot(composeTestRule) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ProgramEventTest : BaseTest() {
prepareProgramAndLaunchActivity(atenatalCare)

programEventsRobot {
clickOnEvent(eventDate, eventOrgUnit)
clickOnEvent(eventDate)
}

eventRobot {
Expand All @@ -84,7 +84,7 @@ class ProgramEventTest : BaseTest() {
disableRecyclerViewAnimations()

programEventsRobot {
clickOnEvent(eventDate, eventOrgUnit)
clickOnEvent(eventDate)
}

eventRobot {
Expand All @@ -95,7 +95,7 @@ class ProgramEventTest : BaseTest() {

programEventsRobot {
checkEventIsComplete(eventDate, eventOrgUnit)
clickOnEvent(eventDate, eventOrgUnit)
clickOnEvent(eventDate)
}

eventRobot {
Expand All @@ -118,7 +118,7 @@ class ProgramEventTest : BaseTest() {
prepareProgramAndLaunchActivity(atenatalCare)

programEventsRobot {
clickOnEvent(eventDate, eventOrgUnit)
clickOnEvent(eventDate)
}
eventRobot {
clickOnDetails()
Expand All @@ -135,7 +135,7 @@ class ProgramEventTest : BaseTest() {
disableRecyclerViewAnimations()

programEventsRobot {
clickOnEvent(eventDate, eventOrgUnit)
clickOnEvent(eventDate)
}
eventRobot {
openMenuMoreOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItem
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withTagValue
import androidx.test.espresso.matcher.ViewMatchers.withText
import org.dhis2.R
import org.dhis2.common.BaseRobot
import org.dhis2.common.matchers.RecyclerviewMatchers.Companion.hasItem
Expand All @@ -23,19 +27,14 @@ fun programEventsRobot(programEventsRobot: ProgramEventsRobot.() -> Unit) {

class ProgramEventsRobot : BaseRobot() {

fun clickOnEvent(eventDate: String, eventOrgUnit: String) {
fun clickOnEvent(eventDate: String) {
onView(withId(R.id.recycler)).perform(
RecyclerViewActions.scrollTo<EventViewHolder>(
allOf(
hasDescendant(withText(eventDate)),
hasDescendant(withText(eventOrgUnit))
)
hasDescendant(withText(eventDate)),
),
actionOnItem<EventViewHolder>(
allOf(
hasDescendant(withText(eventDate)),
hasDescendant(withText(eventOrgUnit))
), click()
hasDescendant(withText(eventDate)),
click(),
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class SearchTETest : BaseTest() {
@Test
fun shouldSuccessfullySearchByName() {
val firstName = "Tim"
val firstNamePosition = 0
val orgUnit = "Ngelehun CHC"

prepareChildProgrammeIntentAndLaunchActivity(rule)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnOpenSearch()
typeAttributeAtPosition(firstName, firstNamePosition)
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(firstName)
clickOnSearch()
checkListOfSearchTEI(firstName, orgUnit)
}
Expand All @@ -76,13 +76,13 @@ class SearchTETest : BaseTest() {
@Test
fun shouldShowErrorWhenCanNotFindSearchResult() {
val firstName = "asdssds"
val firstNamePosition = 1

prepareTestProgramRulesProgrammeIntentAndLaunchActivity(rule)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnOpenSearch()
typeAttributeAtPosition(firstName, firstNamePosition)
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(firstName)
clickOnSearch()
checkNoSearchResult()
}
Expand All @@ -91,16 +91,16 @@ class SearchTETest : BaseTest() {
@Test
fun shouldSuccessfullySearchUsingMoreThanOneField() {
val firstName = "Anna"
val firstNamePosition = 0
val lastName = "Jones"
val lastNamePosition = 1

prepareChildProgrammeIntentAndLaunchActivity(rule)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnOpenSearch()
typeAttributeAtPosition(firstName, firstNamePosition)
typeAttributeAtPosition(lastName, lastNamePosition)
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(firstName)
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(lastName)
clickOnSearch()
checkListOfSearchTEI(firstName, lastName)
}
Expand All @@ -113,7 +113,7 @@ class SearchTETest : BaseTest() {

prepareChildProgrammeIntentAndLaunchActivity(rule)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnProgramSpinner()
selectAProgram(tbProgram)
checkProgramHasChanged(tbProgram)
Expand All @@ -122,23 +122,20 @@ class SearchTETest : BaseTest() {

@Test
fun shouldCheckDisplayInList() {
val birthdaySearch = createDateOfBirthSearch()
val displayInListData = createDisplayListFields()
val namePosition = 0
val lastNamePosition = 1

setDatePicker()
prepareTestAdultWomanProgrammeIntentAndLaunchActivity(rule)

searchTeiRobot {
typeAttributeAtPosition(displayInListData.name, namePosition)
typeAttributeAtPosition(displayInListData.lastName, lastNamePosition)
clickOnDateField()
selectSpecificDate(birthdaySearch.year, birthdaySearch.month, birthdaySearch.day)
acceptDate()
searchTeiRobot(composeTestRule) {
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(displayInListData.name)
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(displayInListData.lastName)
openNextSearchParameter("Date of birth")
typeOnDateParameter("01012001")
clickOnSearch()
checkFieldsFromDisplayList(
composeTestRule,
displayInListData,
)
}
Expand Down Expand Up @@ -179,7 +176,7 @@ class SearchTETest : BaseTest() {
prepareTestAdultWomanProgrammeIntentAndLaunchActivity(rule)

teiFlowRobot {
registerTEI(registerTeiDetails)
registerTEI(registerTeiDetails, composeTestRule)
changeDueDate(overdueDate, programStage, orgUnit, composeTestRule)
pressBack()
composeTestRule.onNodeWithTag(SECONDARY_BUTTON_TAG).performClick()
Expand Down Expand Up @@ -276,16 +273,16 @@ class SearchTETest : BaseTest() {
fun shouldSuccessfullyFilterBySync() {
val teiName = "Frank"
val teiLastName = "Fjordsen"
val firstNamePosition = 0
val lastNamePosition = 1
val syncFilter = context.getString(R.string.action_sync)
val totalCount = "1"
prepareChildProgrammeIntentAndLaunchActivity(rule)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnOpenSearch()
typeAttributeAtPosition(teiName, firstNamePosition)
typeAttributeAtPosition(teiLastName, lastNamePosition)
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(teiName)
openNextSearchParameter("Last name")
typeOnNextSearchTextParameter(teiLastName)
clickOnSearch()
clickOnTEI(teiName, teiLastName)
}
Expand All @@ -311,17 +308,17 @@ class SearchTETest : BaseTest() {
fun shouldSuccessfullySearchAndFilter() {
val name = "Anna"
val lastName = "Jones"
val namePosition = 0
val enrollmentStatus = context.getString(R.string.filters_title_enrollment_status)
.format(context.resources.getQuantityString(R.plurals.enrollment, 1).capitalize(Locale.current))
val totalCount = "2"
val totalFilterCount = "1"

prepareChildProgrammeIntentAndLaunchActivity(rule)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnOpenSearch()
typeAttributeAtPosition(name, namePosition)
openNextSearchParameter("First name")
typeOnNextSearchTextParameter(name)
clickOnSearch()
}

Expand All @@ -336,7 +333,7 @@ class SearchTETest : BaseTest() {
checkTEIsAreOpen()
}

searchTeiRobot {
searchTeiRobot(composeTestRule) {
checkListOfSearchTEI(name, lastName)
}
}
Expand All @@ -347,7 +344,7 @@ class SearchTETest : BaseTest() {

prepareChildProgrammeIntentAndLaunchActivity(rule)

searchTeiRobot {
searchTeiRobot(composeTestRule) {
clickOnShowMap()
try {
val device = UiDevice.getInstance(getInstrumentation())
Expand Down
Loading

0 comments on commit a0899a5

Please sign in to comment.