Skip to content

Commit a4ec38c

Browse files
authored
fix: [ANDROAPP-7666] don't show "mark as complete?" dialog for completed events with no issues (#4912)
In showDataEntryResultDialogDeprecated(), the EventStatus.COMPLETED branch computed FormActions.OnFinish for a completed event with no field issues, but discarded it as a dangling expression and always fell through to resultAction, which shows the "mark as complete?" dialog. As a result, opening or saving an already-completed event with no issues always prompted the user to mark it as complete, even though it already was. Return FormActions.OnFinish in that case instead of always showing the dialog.
1 parent dbe9234 commit a4ec38c

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

form/src/main/java/org/dhis2/form/ui/FormViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,9 @@ class FormViewModel(
887887
val resultAction = provideShowResultDialog(result)
888888
if (resultAction?.fieldsWithIssues?.isEmpty() == true) {
889889
FormActions.OnFinish
890+
} else {
891+
resultAction
890892
}
891-
resultAction
892893
}
893894

894895
EventStatus.SKIPPED -> {

form/src/test/java/org/dhis2/form/ui/FormViewModelTest.kt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import android.content.Intent
44
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
55
import kotlinx.coroutines.Dispatchers
66
import kotlinx.coroutines.ExperimentalCoroutinesApi
7+
import kotlinx.coroutines.flow.first
78
import kotlinx.coroutines.runBlocking
89
import kotlinx.coroutines.test.StandardTestDispatcher
910
import kotlinx.coroutines.test.advanceUntilIdle
1011
import kotlinx.coroutines.test.runTest
1112
import kotlinx.coroutines.test.setMain
13+
import org.dhis2.commons.dialogs.bottomsheet.BottomSheetDialogUiModel
1214
import org.dhis2.commons.viewmodel.DispatcherProvider
15+
import org.dhis2.form.data.EventResultDetails
1316
import org.dhis2.form.data.FormRepository
1417
import org.dhis2.form.data.GeometryController
18+
import org.dhis2.form.data.SuccessfulResult
1519
import org.dhis2.form.model.ActionType
20+
import org.dhis2.form.model.EventMode
1621
import org.dhis2.form.model.FieldUiModel
1722
import org.dhis2.form.model.RowAction
1823
import org.dhis2.form.ui.event.RecyclerViewUiEvents
@@ -21,12 +26,14 @@ import org.dhis2.form.ui.mapper.FormSectionMapper
2126
import org.dhis2.form.ui.provider.FormResultDialogProvider
2227
import org.dhis2.mobile.commons.model.CustomIntentRequestArgumentModel
2328
import org.hisp.dhis.android.core.common.ValueType
29+
import org.hisp.dhis.android.core.event.EventStatus
2430
import org.junit.Assert.assertEquals
2531
import org.junit.Assert.assertTrue
2632
import org.junit.Before
2733
import org.junit.Rule
2834
import org.junit.Test
2935
import org.mockito.kotlin.any
36+
import org.mockito.kotlin.anyOrNull
3037
import org.mockito.kotlin.doReturn
3138
import org.mockito.kotlin.mock
3239
import org.mockito.kotlin.verify
@@ -201,4 +208,50 @@ class FormViewModelTest {
201208

202209
verify(repository).save(fieldUid, null, null)
203210
}
211+
212+
@Test
213+
fun `Should not show result dialog for an already completed event with no issues`() =
214+
runTest {
215+
givenACompletedEventWithNoIssues()
216+
217+
viewModel.runDataIntegrityCheck()
218+
advanceUntilIdle()
219+
220+
val action = viewModel.actionsChannel.first()
221+
assertEquals(FormViewModel.FormActions.OnFinish, action)
222+
}
223+
224+
private suspend fun givenACompletedEventWithNoIssues() {
225+
val result =
226+
SuccessfulResult(
227+
canComplete = true,
228+
onCompleteMessage = null,
229+
eventResultDetails =
230+
EventResultDetails(
231+
eventStatus = EventStatus.COMPLETED,
232+
eventMode = EventMode.CHECK,
233+
validationStrategy = null,
234+
),
235+
)
236+
whenever(repository.isEvent()) doReturn true
237+
whenever(repository.isEventEditable()) doReturn true
238+
whenever(repository.runDataIntegrityCheck(backPressed = false)) doReturn result
239+
whenever(repository.composeList()) doReturn emptyList()
240+
whenever(
241+
resultDialogUiProvider(
242+
canComplete = any(),
243+
onCompleteMessage = anyOrNull(),
244+
errorFields = any(),
245+
emptyMandatoryFields = any(),
246+
warningFields = any(),
247+
eventMode = anyOrNull(),
248+
eventState = anyOrNull(),
249+
result = any(),
250+
),
251+
) doReturn
252+
Pair(
253+
BottomSheetDialogUiModel(title = "title", iconResource = 0),
254+
emptyList(),
255+
)
256+
}
204257
}

0 commit comments

Comments
 (0)