Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Feb 6, 2024
1 parent a00a5c9 commit eb1da73
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ 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
import org.dhis2.usescases.teidashboard.robot.enrollmentRobot
import org.dhis2.usescases.teidashboard.robot.eventRobot
import org.dhis2.usescases.teidashboard.robot.teiDashboardRobot
Expand Down Expand Up @@ -77,23 +77,31 @@ class TeiFlowRobot : BaseRobot() {

teiDashboardRobot {
checkCompleteStateInfoBarIsDisplay(composeTestRule)
checkCanNotAddEvent()
checkCanNotAddEvent(composeTestRule)
checkAllEventsAreClosed(totalEvents)
}
}

fun closeEnrollmentAndCheckEvents(totalEvents: Int) {
fun closeEnrollmentAndCheckEvents(
composeTestRule: ComposeContentTestRule,
totalEvents: Int
) {
teiDashboardRobot {
clickOnMenuMoreOptions()
clickOnTimelineEvents()
clickOnMenuMoreOptions()
clickOnMenuComplete()
checkCanNotAddEvent()
checkCanNotAddEvent(composeTestRule)
checkAllEventsAreClosed(totalEvents)
}
}

fun changeDueDate(date: DateRegistrationUIModel, programStage: String, orgUnit: String, composeTestRule: ComposeTestRule) {
fun changeDueDate(
date: DateRegistrationUIModel,
programStage: String,
orgUnit: String,
composeTestRule: ComposeTestRule
) {
teiDashboardRobot {
clickOnStageGroup(programStage)
clickOnEventGroupByStageUsingOU(orgUnit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TeiFlowTest: BaseTest() {

teiFlowRobot {
registerTEI(registerTeiDetails)
closeEnrollmentAndCheckEvents(totalEventsPerEnrollment)
closeEnrollmentAndCheckEvents(composeTestRule,totalEventsPerEnrollment)
enrollToProgram(composeTestRule, ADULT_WOMAN_PROGRAM)
checkActiveAndPastEnrollmentDetails(enrollmentListDetails)
checkPastEventsAreClosed(composeTestRule, totalEventsPerEnrollment, pastProgramPosition)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.dhis2.usescases.teidashboard.robot.eventRobot
import org.dhis2.usescases.teidashboard.robot.indicatorsRobot
import org.dhis2.usescases.teidashboard.robot.noteRobot
import org.dhis2.usescases.teidashboard.robot.teiDashboardRobot
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -103,7 +104,7 @@ class TeiDashboardTest : BaseTest() {
clickOnMenuMoreOptions()
clickOnMenuDeactivate()
checkCancelledStateInfoBarIsDisplay(composeTestRule)
checkCanNotAddEvent()
checkCanNotAddEvent(composeTestRule)
checkAllEventsAreInactive(1)
}
}
Expand All @@ -118,7 +119,7 @@ class TeiDashboardTest : BaseTest() {
clickOnMenuMoreOptions()
clickOnMenuComplete()
checkCompleteStateInfoBarIsDisplay(composeTestRule)
checkCanNotAddEvent()
checkCanNotAddEvent(composeTestRule)
checkAllEventsAreClosed(1)
}
}
Expand All @@ -141,8 +142,8 @@ class TeiDashboardTest : BaseTest() {
teiDashboardRobot {
clickOnMenuMoreOptions()
clickOnTimelineEvents()
clickOnFab()
clickOnReferral()
clickOnFab(composeTestRule)
clickOnReferral(composeTestRule)
clickOnFirstReferralEvent()
clickOnReferralOption(
composeTestRule,
Expand All @@ -160,8 +161,8 @@ class TeiDashboardTest : BaseTest() {
teiDashboardRobot {
clickOnMenuMoreOptions()
clickOnTimelineEvents()
clickOnFab()
clickOnScheduleNew()
clickOnFab(composeTestRule)
clickOnScheduleNew(composeTestRule)
clickOnFirstReferralEvent()
clickOnReferralNextButton()
checkEventWasCreatedWithDate(LAB_MONITORING, LAB_MONITORING_SCHEDULE_DATE)
Expand All @@ -188,6 +189,7 @@ class TeiDashboardTest : BaseTest() {
}
}

@Ignore("This is checking xml instead of compose. Update mobile library with test tags.")
@Test
fun shouldShowCorrectInfoWhenOpenTEI() {
prepareTeiCompletedProgrammeAndLaunchActivity(rule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.dhis2.usescases.teidashboard.robot
import android.content.Context
import android.view.View
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.junit4.ComposeTestRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
Expand All @@ -17,7 +18,6 @@ import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.hasSibling
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isEnabled
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withTagValue
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand All @@ -36,9 +36,9 @@ import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.DashboardProg
import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.teievents.EventViewHolder
import org.dhis2.usescases.teiDashboard.dashboardfragments.teidata.teievents.StageViewHolder
import org.dhis2.usescases.teiDashboard.ui.STATE_INFO_BAR_TEST_TAG
import org.dhis2.usescases.teiDashboard.ui.TEST_ADD_EVENT_BUTTON
import org.dhis2.usescases.teidashboard.entity.EnrollmentUIModel
import org.dhis2.usescases.teidashboard.entity.UpperEnrollmentUIModel
import org.dhis2.utils.dialFloatingActionButton.FAB_ID
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.anyOf
import org.hamcrest.CoreMatchers.equalTo
Expand Down Expand Up @@ -86,13 +86,6 @@ class TeiDashboardRobot : BaseRobot() {
composeTestRule.onNodeWithText("Enrollment cancelled").assertIsDisplayed()
}

fun checkCanAddEvent() {
onView(withId(FAB_ID)).check(matches(allOf(isDisplayed(), isEnabled()))).perform(click())
val targetContext: Context = InstrumentationRegistry.getInstrumentation().targetContext
val addNewTag = targetContext.resources.getString(R.string.add_new)
onView(withTagValue(equalTo(addNewTag))).check(matches(isDisplayed()))
}

fun clickOnEventWithPosition(position: Int) {
onView(withId(R.id.tei_recycler))
.perform(actionOnItemAtPosition<DashboardProgramViewHolder>(position, click()))
Expand Down Expand Up @@ -135,14 +128,15 @@ class TeiDashboardRobot : BaseRobot() {
)
}

fun clickOnFab() {
onView(withId(FAB_ID)).perform(click())
fun clickOnFab(composeTestRule: ComposeTestRule) {
composeTestRule.onNodeWithTag(TEST_ADD_EVENT_BUTTON,useUnmergedTree = true).performClick()
}

fun clickOnReferral() {
fun clickOnReferral(composeTestRule: ComposeTestRule) {
val targetContext: Context = InstrumentationRegistry.getInstrumentation().targetContext
val referalTag = targetContext.resources.getString(R.string.referral)
onView(withTagValue(equalTo(referalTag))).perform(click())
composeTestRule.onNodeWithTag(referalTag).performClick()
// onView(withTagValue(equalTo(referalTag))).perform(click())
}

fun checkCannotAddMoreEventToastIsShown() {
Expand Down Expand Up @@ -230,8 +224,8 @@ class TeiDashboardRobot : BaseRobot() {
}


fun checkCanNotAddEvent() {
onView(withId(FAB_ID)).check(matches(not(isDisplayed())))
fun checkCanNotAddEvent(composeTestRule: ComposeTestRule) {
composeTestRule.onNodeWithTag(TEST_ADD_EVENT_BUTTON, useUnmergedTree = true).assertDoesNotExist()
}

fun clickOnShareButton() {
Expand Down Expand Up @@ -312,10 +306,11 @@ class TeiDashboardRobot : BaseRobot() {
}
})
}
fun clickOnScheduleNew() {

fun clickOnScheduleNew(composeTestRule: ComposeTestRule) {
val targetContext: Context = InstrumentationRegistry.getInstrumentation().targetContext
val scheduleTag = targetContext.resources.getString(R.string.schedule_new)
onView(withTagValue(equalTo(scheduleTag))).perform(click())
composeTestRule.onNodeWithTag(scheduleTag, useUnmergedTree = true).performClick()
}

fun clickOnMenuProgramEnrollments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,6 @@ class TeiDashboardMobileActivity :
override fun updateStatus() {
}

/*fun updatedEnrollment(): LiveData<String>? {
return currentEnrollment
}*/

override fun displayStatusError(statusCode: StatusChangeResultCode) {
when (statusCode) {
StatusChangeResultCode.FAILED -> displayMessage(getString(R.string.something_wrong))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ class TEIDataContracts {

fun showProgramRuleErrorMessage()
fun goToEventInitial(eventCreationType: EventCreationType, programStage: ProgramStage)
fun updateEnrollment(update: Boolean)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {

with(dashboardViewModel) {
eventUid().observe(viewLifecycleOwner, ::displayGenerateEvent)
updateEnrollment.observe(viewLifecycleOwner) { update ->
updateEnrollment(update)
}
}

presenter.events.observe(viewLifecycleOwner) {
Expand Down Expand Up @@ -405,14 +408,17 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {

override fun openEventDetails(intent: Intent, options: ActivityOptionsCompat) =
contractHandler.scheduleEvent(intent, options).observe(this.viewLifecycleOwner) {
updateEnrollment(true)
}

override fun openEventInitial(intent: Intent) =
contractHandler.editEvent(intent).observe(this.viewLifecycleOwner) {
updateEnrollment(true)
}

override fun openEventCapture(intent: Intent) =
contractHandler.editEvent(intent).observe(this.viewLifecycleOwner) {
updateEnrollment(true)
}

override fun goToEventInitial(
Expand Down Expand Up @@ -441,6 +447,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
bundle.putInt(Constants.EVENT_SCHEDULE_INTERVAL, programStage.standardInterval() ?: 0)
intent.putExtras(bundle)
contractHandler.createEvent(intent).observe(this.viewLifecycleOwner) {
updateEnrollment(true)
}
}
}
Expand Down Expand Up @@ -469,6 +476,12 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
}
}

override fun updateEnrollment(update: Boolean) {
presenter.fetchEvents(update)
presenter.getEnrollment()?.let { eventAdapter?.setEnrollment(it) }
dashboardViewModel.updateDashboard()
}

companion object {
const val RC_GENERATE_EVENT = 1501
const val RC_EVENTS_COMPLETED = 1601
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.dhis2.utils.analytics.CREATE_EVENT_TEI
import org.dhis2.utils.analytics.FOLLOW_UP
import org.dhis2.utils.analytics.TYPE_EVENT_TEI
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.enrollment.Enrollment
import org.hisp.dhis.android.core.enrollment.EnrollmentStatus
import org.hisp.dhis.android.core.event.EventStatus
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
Expand Down Expand Up @@ -303,6 +304,7 @@ class TEIDataPresenter(
val intent = Intent(view.context, ProgramStageSelectionActivity::class.java)
intent.putExtras(bundle)
contractHandler.createEvent(intent).observe(view.viewLifecycleOwner()) {
view.updateEnrollment(true)
}
}

Expand Down Expand Up @@ -409,4 +411,14 @@ class TEIDataPresenter(
val options = programUid?.let { getNewEventCreationTypeOptions(stage, it) }
return options?.let { eventCreationOptionsMapper.mapToEventsByStage(it) } ?: emptyList()
}

fun fetchEvents(updateEnrollment: Boolean) {
if (updateEnrollment) {
groupingProcessor.onNext(groupingProcessor.value)
}
}

fun getEnrollment(): Enrollment? {
return teiDataRepository.getEnrollment().blockingGet()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.tooling.preview.Preview
import org.dhis2.R
Expand All @@ -30,6 +32,7 @@ fun NewEventOptions(

Column {
IconButton(
modifier = Modifier.testTag(TEST_ADD_EVENT_BUTTON),
style = IconButtonStyle.FILLED,
icon = {
Icon(
Expand All @@ -46,6 +49,7 @@ fun NewEventOptions(
) {
options.forEach {
DropdownMenuItem(
modifier = Modifier.testTag(it.name),
content = { Text(it.name) },
onClick = {
onOptionSelected.invoke(it.type)
Expand Down Expand Up @@ -75,3 +79,5 @@ fun NewEventOptionsPreview() {
}

data class EventCreationOptions(val type: EventCreationType, val name: String)

const val TEST_ADD_EVENT_BUTTON = "TEST_ADD_EVENT_BUTTON"

0 comments on commit eb1da73

Please sign in to comment.