diff --git a/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt b/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt index 0f0ef7320a..f4a7ddc5c7 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowRobot.kt @@ -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 @@ -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) diff --git a/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowTest.kt b/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowTest.kt index d6d4a28036..14e3efdb69 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowTest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/flow/teiFlow/TeiFlowTest.kt @@ -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) diff --git a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/TeiDashboardTest.kt b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/TeiDashboardTest.kt index d080db8ae1..b730192501 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/TeiDashboardTest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/TeiDashboardTest.kt @@ -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 @@ -103,7 +104,7 @@ class TeiDashboardTest : BaseTest() { clickOnMenuMoreOptions() clickOnMenuDeactivate() checkCancelledStateInfoBarIsDisplay(composeTestRule) - checkCanNotAddEvent() + checkCanNotAddEvent(composeTestRule) checkAllEventsAreInactive(1) } } @@ -118,7 +119,7 @@ class TeiDashboardTest : BaseTest() { clickOnMenuMoreOptions() clickOnMenuComplete() checkCompleteStateInfoBarIsDisplay(composeTestRule) - checkCanNotAddEvent() + checkCanNotAddEvent(composeTestRule) checkAllEventsAreClosed(1) } } @@ -141,8 +142,8 @@ class TeiDashboardTest : BaseTest() { teiDashboardRobot { clickOnMenuMoreOptions() clickOnTimelineEvents() - clickOnFab() - clickOnReferral() + clickOnFab(composeTestRule) + clickOnReferral(composeTestRule) clickOnFirstReferralEvent() clickOnReferralOption( composeTestRule, @@ -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) @@ -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) diff --git a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/TeiDashboardRobot.kt b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/TeiDashboardRobot.kt index 4b9540e94e..8c0ed78e5a 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/TeiDashboardRobot.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/teidashboard/robot/TeiDashboardRobot.kt @@ -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 @@ -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 @@ -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 @@ -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(position, click())) @@ -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() { @@ -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() { @@ -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() { diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt index 07b9fc050f..69f1d7fe39 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/TeiDashboardMobileActivity.kt @@ -621,10 +621,6 @@ class TeiDashboardMobileActivity : override fun updateStatus() { } - /*fun updatedEnrollment(): LiveData? { - return currentEnrollment - }*/ - override fun displayStatusError(statusCode: StatusChangeResultCode) { when (statusCode) { StatusChangeResultCode.FAILED -> displayMessage(getString(R.string.something_wrong)) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt index 2a74380ab4..5a0c408e8c 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataContracts.kt @@ -40,5 +40,6 @@ class TEIDataContracts { fun showProgramRuleErrorMessage() fun goToEventInitial(eventCreationType: EventCreationType, programStage: ProgramStage) + fun updateEnrollment(update: Boolean) } } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt index e1c0dc74a3..08c611fc74 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataFragment.kt @@ -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) { @@ -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( @@ -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) } } } @@ -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 diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt index 5c012d7235..0e9f11cad7 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/dashboardfragments/teidata/TEIDataPresenter.kt @@ -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 @@ -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) } } @@ -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() + } } diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/ui/NewEventOptionsMenu.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/ui/NewEventOptionsMenu.kt index 3749e15c84..2adc0de062 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/ui/NewEventOptionsMenu.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/ui/NewEventOptionsMenu.kt @@ -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 @@ -30,6 +32,7 @@ fun NewEventOptions( Column { IconButton( + modifier = Modifier.testTag(TEST_ADD_EVENT_BUTTON), style = IconButtonStyle.FILLED, icon = { Icon( @@ -46,6 +49,7 @@ fun NewEventOptions( ) { options.forEach { DropdownMenuItem( + modifier = Modifier.testTag(it.name), content = { Text(it.name) }, onClick = { onOptionSelected.invoke(it.type) @@ -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"