From af7b352171271f869b31307dc959172c668da99e Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 29 Apr 2024 17:16:54 +0200 Subject: [PATCH] version name 3.0 (#3605) Signed-off-by: Pablo --- .../teiDashboard/DashboardViewModel.kt | 3 +-- .../teidata/TEIDataContracts.kt | 1 - .../teidata/TEIDataFragment.kt | 18 ++++-------------- .../teidata/TEIDataPresenter.kt | 8 +++----- .../teiDashboard/DashboardViewModelTest.kt | 8 +++++++- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardViewModel.kt b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardViewModel.kt index 22649f3b1d..7523decc33 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardViewModel.kt +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/DashboardViewModel.kt @@ -27,7 +27,6 @@ class DashboardViewModel( private val eventUid = MutableLiveData() - val updateEnrollment = MutableLiveData(false) val showStatusErrorMessages = MutableLiveData(StatusChangeResultCode.CHANGED) private var _showFollowUpBar = MutableStateFlow(false) @@ -141,7 +140,7 @@ class DashboardViewModel( _showStatusBar.value = status _syncNeeded.value = true _state.value = State.TO_UPDATE - updateEnrollment.postValue(true) + fetchDashboardModel() } else { showStatusErrorMessages.postValue(result) } 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 27893cf19d..7928e18686 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 @@ -35,7 +35,6 @@ class TEIDataContracts { fun showProgramRuleErrorMessage() fun goToEventInitial(eventCreationType: EventCreationType, programStage: ProgramStage) - fun updateEnrollment(update: Boolean) fun displayOrgUnitSelectorForNewEvent(programUid: String, programStageUid: String) fun goToEventDetails( 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 49daa770b8..102d1c164b 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 @@ -134,9 +134,6 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { with(dashboardViewModel) { eventUid().observe(viewLifecycleOwner, ::displayGenerateEvent) - updateEnrollment.observe(viewLifecycleOwner) { update -> - updateEnrollment(update) - } noEnrollmentSelected.observe(viewLifecycleOwner) { noEnrollmentSelected -> if (noEnrollmentSelected) { showAllEnrollment = true @@ -387,7 +384,7 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { programStageUid, ), ) - presenter.fetchEvents(true) + presenter.fetchEvents() }, ).show(parentFragmentManager, SCHEDULING_DIALOG) } @@ -469,17 +466,17 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { override fun openEventDetails(intent: Intent, options: ActivityOptionsCompat) = contractHandler.scheduleEvent(intent, options).observe(viewLifecycleOwner) { - updateEnrollment(true) + presenter.fetchEvents() } override fun openEventInitial(intent: Intent) = contractHandler.editEvent(intent).observe(viewLifecycleOwner) { - updateEnrollment(true) + presenter.fetchEvents() } override fun openEventCapture(intent: Intent) = contractHandler.editEvent(intent).observe(viewLifecycleOwner) { - updateEnrollment(true) + presenter.fetchEvents() } override fun goToEventInitial( @@ -576,13 +573,6 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View { } } - override fun updateEnrollment(update: Boolean) { - if (update) { - presenter.fetchEvents(update) - dashboardViewModel.updateDashboard() - } - } - companion object { const val RC_EVENTS_COMPLETED = 1601 const val PREF_COMPLETED_EVENT = "COMPLETED_EVENT" 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 7216e851ba..84dd97073a 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 @@ -285,7 +285,7 @@ class TEIDataPresenter( val intent = Intent(view.context, ProgramStageSelectionActivity::class.java) intent.putExtras(bundle) contractHandler.createEvent(intent).observe(view.viewLifecycleOwner()) { - view.updateEnrollment(true) + fetchEvents() } } @@ -395,10 +395,8 @@ class TEIDataPresenter( return options?.let { eventCreationOptionsMapper.mapToEventsByStage(it) } ?: emptyList() } - fun fetchEvents(updateEnrollment: Boolean) { - if (updateEnrollment) { - groupingProcessor.onNext(dashboardRepository.getGrouping()) - } + fun fetchEvents() { + groupingProcessor.onNext(dashboardRepository.getGrouping()) } fun getEnrollment(): Enrollment? { diff --git a/app/src/test/java/org/dhis2/usescases/teiDashboard/DashboardViewModelTest.kt b/app/src/test/java/org/dhis2/usescases/teiDashboard/DashboardViewModelTest.kt index c40aef0da8..1e0c57fe87 100644 --- a/app/src/test/java/org/dhis2/usescases/teiDashboard/DashboardViewModelTest.kt +++ b/app/src/test/java/org/dhis2/usescases/teiDashboard/DashboardViewModelTest.kt @@ -120,13 +120,13 @@ class DashboardViewModelTest { whenever(repository.updateEnrollmentStatus(any(), any())) doReturn Observable.just( StatusChangeResultCode.CHANGED, ) + whenever(mockedEnrollmentModel.currentEnrollment) doReturn mockedCompletedEnrollment updateEnrollmentStatus(EnrollmentStatus.COMPLETED) testingDispatcher.scheduler.advanceUntilIdle() verify(repository).updateEnrollmentStatus("enrollmentUid", EnrollmentStatus.COMPLETED) assertTrue(showStatusBar.value == EnrollmentStatus.COMPLETED) assertTrue(syncNeeded.value) assertTrue(state.value == State.TO_UPDATE) - assertTrue(updateEnrollment.value == true) } } @@ -187,4 +187,10 @@ class DashboardViewModelTest { on { aggregatedSyncState() } doReturn State.SYNCED on { status() } doReturn EnrollmentStatus.ACTIVE } + + private val mockedCompletedEnrollment: Enrollment = mock { + on { uid() } doReturn "enrollmentUid" + on { aggregatedSyncState() } doReturn State.TO_UPDATE + on { status() } doReturn EnrollmentStatus.COMPLETED + } }