Skip to content

Commit

Permalink
Display schedule event dialog when event option of schedule type is s…
Browse files Browse the repository at this point in the history
…elected
  • Loading branch information
msasikanth committed Sep 17, 2024
1 parent 067e158 commit 910274d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TEIDataContracts {
interface View : AbstractActivityContracts.View {
fun viewLifecycleOwner(): LifecycleOwner
fun setEvents(events: List<EventViewModel>)
fun displayScheduleEvent()
fun displayScheduleEvent(showYesNoOptions: Boolean)
fun showDialogCloseProgram()
fun areEventsCompleted(): Consumer<Single<Boolean>>
fun displayGenerateEvent(eventUid: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,13 @@ class TEIDataFragment : FragmentGlobalAbstract(), TEIDataContracts.View {
}
}

override fun displayScheduleEvent() {
override fun displayScheduleEvent(showYesNoOptions: Boolean) {
val model = dashboardViewModel.dashboardModel.value
if (model is DashboardEnrollmentModel) {
SchedulingDialog.newInstance(
enrollment = model.currentEnrollment,
programStages = presenter.filterAvailableStages(model.programStages),
showYesNoOptions = showYesNoOptions,
).show(parentFragmentManager, SCHEDULING_DIALOG)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ class TEIDataPresenter(
val enrollment = d2.enrollment(enrollmentUid)
val showButton =
enrollment != null &&
!isGrouping && enrollment.status() == EnrollmentStatus.ACTIVE &&
canAddNewEvents()
!isGrouping && enrollment.status() == EnrollmentStatus.ACTIVE &&
canAddNewEvents()
_shouldDisplayEventCreationButton.postValue(showButton)
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ class TEIDataPresenter(
.observeOn(schedulerProvider.ui())
.subscribe({ programStage ->
if (programStage.displayGenerateEventBox() == true || programStage.allowGenerateNextVisit() == true) {
view.displayScheduleEvent()
view.displayScheduleEvent(showYesNoOptions = true)
} else if (programStage.remindCompleted() == true) {
view.showDialogCloseProgram()
}
Expand Down Expand Up @@ -359,13 +359,20 @@ class TEIDataPresenter(
}
}

private fun manageAddNewEventOptionSelected(eventCreationType: EventCreationType, stage: ProgramStage?) {
private fun manageAddNewEventOptionSelected(
eventCreationType: EventCreationType,
stage: ProgramStage?
) {
if (stage != null) {
when (eventCreationType) {
EventCreationType.ADDNEW -> programUid?.let { program ->
checkOrgUnitCount(program, stage.uid())
}

EventCreationType.SCHEDULE -> {
view.displayScheduleEvent(showYesNoOptions = false)
}

else -> view.goToEventInitial(eventCreationType, stage)
}
} else {
Expand All @@ -392,10 +399,10 @@ class TEIDataPresenter(
.filter { !stagesToHide.contains(it.uid()) }
.filter { stage ->
stage.repeatable() == true ||
events.value?.none { event ->
event.stage?.uid() == stage.uid() &&
event.type == EventViewModelType.EVENT
} == true
events.value?.none { event ->
event.stage?.uid() == stage.uid() &&
event.type == EventViewModelType.EVENT
} == true
}.sortedBy { stage -> stage.sortOrder() }

fun checkOrgUnitCount(programUid: String, programStageUid: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ class SchedulingDialog : BottomSheetDialogFragment() {
fun newInstance(
enrollment: Enrollment,
programStages: List<ProgramStage>,
showYesNoOptions: Boolean,
): SchedulingDialog {
return SchedulingDialog().apply {
this.enrollment = enrollment
this.programStages = programStages
this.showYesNoOptions = showYesNoOptions
}
}
}

var enrollment: Enrollment? = null
var programStages: List<ProgramStage>? = null
var showYesNoOptions: Boolean = true

@Inject
lateinit var factory: SchedulingViewModelFactory
Expand Down Expand Up @@ -90,6 +93,7 @@ class SchedulingDialog : BottomSheetDialogFragment() {
viewModel = viewModel,
programStages = viewModel.programStages,
orgUnitUid = viewModel.enrollment.organisationUnit(),
showYesNoOptions = showYesNoOptions,
onDismiss = { dismiss() },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import org.dhis2.commons.bindings.canCreateEventInEnrollment
import org.dhis2.commons.bindings.enrollment
import org.dhis2.commons.data.EventCreationType
import org.dhis2.commons.data.EventViewModel
import org.dhis2.commons.data.EventViewModelType
import org.dhis2.commons.resources.D2ErrorUtils
Expand Down Expand Up @@ -202,7 +203,7 @@ class TeiDataPresenterTest {
dashboardRepository.displayGenerateEvent("eventUid"),
) doReturn Observable.just(programStage)
teiDataPresenter.displayGenerateEvent("eventUid")
verify(view).displayScheduleEvent()
verify(view).displayScheduleEvent(showYesNoOptions = true)
}

@Test
Expand Down Expand Up @@ -327,6 +328,19 @@ class TeiDataPresenterTest {
verifyNoMoreInteractions(view)
}

@Test
fun `should display schedule event without yes and no options, when schedule event option is selected`() {
// when
teiDataPresenter.onAddNewEventOptionSelected(
eventCreationType = EventCreationType.SCHEDULE,
stage = ProgramStage.builder().uid("stage").build(),
)

// then
verify(view).displayScheduleEvent(showYesNoOptions = false)
verifyNoMoreInteractions(view)
}

private fun fakeModel(
eventCount: Int = 0,
type: EventViewModelType = EventViewModelType.STAGE,
Expand Down

0 comments on commit 910274d

Please sign in to comment.