Skip to content

Commit

Permalink
Update SearchTETest (dhis2#3525)
Browse files Browse the repository at this point in the history
* Update SearchTETest with lazyActivityScenario and composeTestRule

* fix shouldShowErrorWhenSyncEventFails

* revert Jenkinsfile changes

* shouldShowErrorWhenSyncEventFails click on event item
  • Loading branch information
andresmr authored Mar 10, 2024
1 parent 3c96d86 commit e5cd69d
Show file tree
Hide file tree
Showing 20 changed files with 533 additions and 510 deletions.
22 changes: 11 additions & 11 deletions app/src/androidTest/java/org/dhis2/usescases/event/EventTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class EventTest : BaseTest() {

prepareEventToDeleteIntentAndLaunchActivity(ruleTeiDashboard)

teiDashboardRobot {
clickOnEventGroupByStageUsingDate(composeTestRule, tbVisitDate)
teiDashboardRobot(composeTestRule) {
clickOnEventGroupByStageUsingDate(tbVisitDate)
}

eventRegistrationRobot {
Expand All @@ -58,7 +58,7 @@ class EventTest : BaseTest() {
clickOnDeleteDialog()
}

teiDashboardRobot {
teiDashboardRobot(composeTestRule) {
checkEventWasDeletedStageGroup(tbProgramStages)
}
}
Expand Down Expand Up @@ -98,19 +98,19 @@ class EventTest : BaseTest() {

prepareEventToUpdateIntentAndLaunchActivity(ruleTeiDashboard)

teiDashboardRobot {
clickOnStageGroup(composeTestRule, labMonitoring)
teiDashboardRobot(composeTestRule) {
clickOnStageGroup(labMonitoring)
clickOnEventGroupByStage(eventDate)
}

eventRobot {
eventRobot(composeTestRule) {
fillRadioButtonForm(radioFormLength)
clickOnFormFabButton()
clickOnCompleteButton(composeTestRule)
clickOnCompleteButton()
}

teiDashboardRobot {
clickOnStageGroup(composeTestRule, labMonitoring)
teiDashboardRobot(composeTestRule) {
clickOnStageGroup(labMonitoring)
checkEventStateStageGroup(labMonitoringStatus)
}
}
Expand All @@ -129,10 +129,10 @@ class EventTest : BaseTest() {
eventRegistrationRobot {
clickNextButton()
}
eventRobot {
eventRobot(composeTestRule) {
typeOnRequiredEventForm("125", 1)
clickOnFormFabButton()
checkSecondaryButtonNotVisible(composeTestRule)
checkSecondaryButtonNotVisible()
}
}

Expand Down
50 changes: 25 additions & 25 deletions app/src/androidTest/java/org/dhis2/usescases/filters/FilterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

class FilterTest: BaseTest() {
class FilterTest : BaseTest() {

@get:Rule
val rule = ActivityTestRule(MainActivity::class.java, false, false)
Expand All @@ -37,16 +37,16 @@ class FilterTest: BaseTest() {
filterRobotCommon {
openFilterAtPosition(0)
clickOnFromToDateOption()
selectDate(2020,6,15)
selectDate(2020, 6, 15)
acceptDateSelected()
selectDate(2020,11,7)
selectDate(2020, 11, 7)
acceptDateSelected()
}
homeRobot {
openFilters()
checkItemsInProgram(composeTestRule,3,"Child Programme", "3")
checkItemsInProgram(composeTestRule,5, "Contraceptives Voucher Program", "5")
checkItemsInProgram(composeTestRule,26, "Mortality < 5 years", "4")
checkItemsInProgram(composeTestRule, 3, "Child Programme", "3")
checkItemsInProgram(composeTestRule, 5, "Contraceptives Voucher Program", "5")
checkItemsInProgram(composeTestRule, 26, "Mortality < 5 years", "4")
}
cleanLocalDatabase()
}
Expand All @@ -68,15 +68,15 @@ class FilterTest: BaseTest() {
}
homeRobot {
openFilters()
checkItemsInProgram(composeTestRule,3,"Child Programme", "0")
checkItemsInProgram(composeTestRule,41, "XX TEST EVENT FULL", "2")
checkItemsInProgram(composeTestRule,43, "XX TEST TRACKER PROGRAM", "4")
checkItemsInProgram(composeTestRule, 3, "Child Programme", "0")
checkItemsInProgram(composeTestRule, 41, "XX TEST EVENT FULL", "2")
checkItemsInProgram(composeTestRule, 43, "XX TEST TRACKER PROGRAM", "4")
}
cleanLocalDatabase()
}

@Test
fun checkTreeOrgUnitFilter(){
fun checkTreeOrgUnitFilter() {
startActivity()
setupCredentials()

Expand All @@ -87,15 +87,15 @@ class FilterTest: BaseTest() {
filterRobotCommon {
openFilterAtPosition(1)
clickOnOrgUnitTree()
orgUnitSelectorRobot(composeTestRule){
orgUnitSelectorRobot(composeTestRule) {
selectTreeOrgUnit("OU TEST PARENT")
}
}
homeRobot {
openFilters()
checkItemsInProgram(composeTestRule,3,"Child Programme", "0")
checkItemsInProgram(composeTestRule,41, "XX TEST EVENT FULL", "2")
checkItemsInProgram(composeTestRule,43, "XX TEST TRACKER PROGRAM", "4")
checkItemsInProgram(composeTestRule, 3, "Child Programme", "0")
checkItemsInProgram(composeTestRule, 41, "XX TEST EVENT FULL", "2")
checkItemsInProgram(composeTestRule, 43, "XX TEST TRACKER PROGRAM", "4")
}
cleanLocalDatabase()
}
Expand All @@ -106,15 +106,15 @@ class FilterTest: BaseTest() {
startActivity()

homeRobot {
openProgramByPosition(composeTestRule,0)
openProgramByPosition(composeTestRule, 0)
waitToDebounce(700)
}
eventWithoutRegistrationRobot {
eventWithoutRegistrationRobot(composeTestRule) {
clickOnEventAtPosition(0)
}
eventRobot {
eventRobot(composeTestRule) {
clickOnFormFabButton()
clickOnCompleteButton(composeTestRule)
clickOnCompleteButton()
pressBack()
}
homeRobot {
Expand All @@ -126,8 +126,8 @@ class FilterTest: BaseTest() {
}
homeRobot {
openFilters()
checkItemsInProgram(composeTestRule,0,"Antenatal care visit", "1")
checkItemsInProgram(composeTestRule,3,"Child Programme", "0")
checkItemsInProgram(composeTestRule, 0, "Antenatal care visit", "1")
checkItemsInProgram(composeTestRule, 3, "Child Programme", "0")
}
cleanLocalDatabase()
}
Expand All @@ -139,13 +139,13 @@ class FilterTest: BaseTest() {
startActivity()

homeRobot {
openProgramByPosition(composeTestRule,41)
openProgramByPosition(composeTestRule, 41)
}
eventWithoutRegistrationRobot {
eventWithoutRegistrationRobot(composeTestRule) {
clickOnEventAtPosition(0)
}
formRobot {
clickOnSelectOption("ZZ TEST RULE ACTIONS A", 1,"Hide Field", 1)
clickOnSelectOption("ZZ TEST RULE ACTIONS A", 1, "Hide Field", 1)
pressBack()
pressBack()
pressBack()
Expand All @@ -164,9 +164,9 @@ class FilterTest: BaseTest() {
}
homeRobot {
openFilters()
checkItemsInProgram(composeTestRule,37,"TB program", "0")
checkItemsInProgram(composeTestRule, 37, "TB program", "0")
waitToDebounce(700)
checkItemsInProgram(composeTestRule,41, "XX TEST EVENT FULL", "1")
checkItemsInProgram(composeTestRule, 41, "XX TEST EVENT FULL", "1")
waitToDebounce(700)
}
cleanLocalDatabase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.dhis2.usescases.flow.searchFlow

import android.content.Intent
import androidx.compose.ui.test.junit4.createComposeRule
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 Down Expand Up @@ -33,13 +33,16 @@ class SearchFlowTest : BaseTest() {
setDatePicker()
val registerTEIDetails = createRegisterTEI()
val enrollmentStatus = context.getString(R.string.filters_title_enrollment_status)
.format(context.resources.getQuantityString(R.plurals.enrollment, 1).capitalize(Locale.current))
.format(
context.resources.getQuantityString(R.plurals.enrollment, 1)
.capitalize(Locale.current)
)
val filterCounter = "1"
val filterTotalCount = "2"
prepareWomanProgrammeIntentAndLaunchActivity(rule)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import androidx.compose.ui.test.performClick
import androidx.lifecycle.MutableLiveData
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import androidx.work.Data
import androidx.work.WorkInfo
import org.dhis2.AppTest
import org.dhis2.lazyActivityScenarioRule
import org.dhis2.usescases.BaseTest
import org.dhis2.usescases.datasets.dataSetTableRobot
import org.dhis2.usescases.datasets.datasetDetail.DataSetDetailActivity
Expand All @@ -31,14 +31,14 @@ import java.util.UUID
class SyncFlowTest : BaseTest() {

@get:Rule
val ruleDataSet = ActivityTestRule(DataSetDetailActivity::class.java, false, false)
val ruleDataSet = lazyActivityScenarioRule<DataSetDetailActivity>(launchActivity = false)

@get:Rule
val ruleSearch = ActivityTestRule(SearchTEActivity::class.java, false, false)
val ruleSearch = lazyActivityScenarioRule<SearchTEActivity>(launchActivity = false)

@get:Rule
val ruleEventWithoutRegistration =
ActivityTestRule(ProgramEventDetailActivity::class.java, false, false)
lazyActivityScenarioRule<ProgramEventDetailActivity>(launchActivity = false)

@get:Rule
val composeTestRule = createComposeRule()
Expand Down Expand Up @@ -68,26 +68,26 @@ class SyncFlowTest : BaseTest() {
clickOnTEI(teiName, teiLastName)
}

teiDashboardRobot {
clickOnEventWith(composeTestRule, LAB_MONITORING_EVENT_DATE)
teiDashboardRobot(composeTestRule) {
clickOnEventWith(LAB_MONITORING_EVENT_DATE)
}

eventRobot {
eventRobot(composeTestRule) {
fillRadioButtonForm(4)
clickOnFormFabButton()
clickOnCompleteButton(composeTestRule)
clickOnCompleteButton()
}

teiDashboardRobot {
teiDashboardRobot(composeTestRule) {
composeTestRule.onNodeWithText("Sync").performClick()
}

syncFlowRobot {
syncFlowRobot(composeTestRule) {
waitToDebounce(500)
clickOnSyncButton(composeTestRule)
clickOnSyncButton()
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.RUNNING)))
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.FAILED)))
checkSyncFailed(composeTestRule)
checkSyncFailed()
}
cleanLocalDatabase()
}
Expand All @@ -97,21 +97,21 @@ class SyncFlowTest : BaseTest() {
fun shouldSuccessfullySyncSavedEvent() {
prepareMalariaEventIntentAndLaunchActivity(ruleEventWithoutRegistration)

eventWithoutRegistrationRobot {
eventWithoutRegistrationRobot(composeTestRule) {
clickOnEventAtPosition(0)
}

eventRobot {
eventRobot(composeTestRule) {
clickOnFormFabButton()
clickOnCompleteButton(composeTestRule)
clickOnCompleteButton()
}

syncFlowRobot {
clickOnEventToSync(0)
clickOnSyncButton(composeTestRule)
syncFlowRobot(composeTestRule) {
clickOnEventToSync()
clickOnSyncButton()
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.RUNNING)))
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.SUCCEEDED)))
checkSyncWasSuccessfully(composeTestRule)
checkSyncWasSuccessfully()
}
cleanLocalDatabase()
}
Expand All @@ -120,21 +120,21 @@ class SyncFlowTest : BaseTest() {
fun shouldShowErrorWhenSyncEventFails() {
prepareMalariaEventIntentAndLaunchActivity(ruleEventWithoutRegistration)

eventWithoutRegistrationRobot {
eventWithoutRegistrationRobot(composeTestRule) {
clickOnEventAtPosition(1)
}

eventRobot {
eventRobot(composeTestRule) {
clickOnFormFabButton()
clickOnCompleteButton(composeTestRule)
clickOnCompleteButton()
}

syncFlowRobot {
clickOnEventToSync(1)
clickOnSyncButton(composeTestRule)
syncFlowRobot(composeTestRule) {
clickOnEventToSync()
clickOnSyncButton()
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.RUNNING)))
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.FAILED)))
checkSyncFailed(composeTestRule)
checkSyncFailed()
}
cleanLocalDatabase()
}
Expand Down Expand Up @@ -162,12 +162,12 @@ class SyncFlowTest : BaseTest() {
clickOnNegativeButton()
}

syncFlowRobot {
syncFlowRobot(composeTestRule) {
clickOnDataSetToSync(0)
clickOnSyncButton(composeTestRule)
clickOnSyncButton()
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.RUNNING)))
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.SUCCEEDED)))
checkSyncWasSuccessfully(composeTestRule) //sync failed
checkSyncWasSuccessfully() //sync failed
}
cleanLocalDatabase()
}
Expand Down Expand Up @@ -195,12 +195,12 @@ class SyncFlowTest : BaseTest() {
clickOnNegativeButton()
}

syncFlowRobot {
syncFlowRobot(composeTestRule) {
clickOnDataSetToSync(1)
clickOnSyncButton(composeTestRule)
clickOnSyncButton()
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.RUNNING)))
workInfoStatusLiveData.postValue(arrayListOf(mockedGranularWorkInfo(WorkInfo.State.FAILED)))
checkSyncFailed(composeTestRule)
checkSyncFailed()
}
cleanLocalDatabase()
}
Expand All @@ -218,10 +218,6 @@ class SyncFlowTest : BaseTest() {
}

companion object {
const val ORG_UNIT = "Ngelehun CHC"
const val TB_VISIT = "TB visit"
const val TB_VISIT_EVENT_DATE = "3/7/2019"
const val LAB_MONITORING = "Lab monitoring"
const val LAB_MONITORING_EVENT_DATE = "28/6/2020"
}
}
Loading

0 comments on commit e5cd69d

Please sign in to comment.