From 3451586c89f7258aadf5a1e7345f22c4fd85d545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manu=20Mu=C3=B1oz?= Date: Wed, 11 Dec 2024 17:28:55 +0100 Subject: [PATCH] fix: [ANDROAPP-6667] add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manu Muñoz --- .../provider/FormResultDialogProviderTest.kt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/form/src/test/java/org/dhis2/form/ui/provider/FormResultDialogProviderTest.kt b/form/src/test/java/org/dhis2/form/ui/provider/FormResultDialogProviderTest.kt index 19ab6cb028..d40e34ffce 100644 --- a/form/src/test/java/org/dhis2/form/ui/provider/FormResultDialogProviderTest.kt +++ b/form/src/test/java/org/dhis2/form/ui/provider/FormResultDialogProviderTest.kt @@ -7,6 +7,7 @@ import org.dhis2.form.data.MissingMandatoryResult import org.dhis2.form.data.SuccessfulResult import org.dhis2.form.model.EventMode import org.dhis2.ui.dialogs.bottomsheet.DialogButtonStyle +import org.dhis2.ui.dialogs.bottomsheet.IssueType import org.hisp.dhis.android.core.common.ValidationStrategy import org.hisp.dhis.android.core.event.EventStatus import org.junit.Assert.assertTrue @@ -98,6 +99,54 @@ class FormResultDialogProviderTest { assertTrue(noErrorsInFormModel.first.mainButton == DialogButtonStyle.CompleteButton) } + @Test + fun `Should configure to show warning on complete message`() { + val completedEventWithNoErrors = SuccessfulResult( + canComplete = true, + onCompleteMessage = "Warning on complete", + eventResultDetails = EventResultDetails( + eventStatus = EventStatus.ACTIVE, + eventMode = EventMode.CHECK, + validationStrategy = ValidationStrategy.ON_COMPLETE, + ), + ) + val noErrorsInFormModel = formResultDialogProvider.invoke( + canComplete = completedEventWithNoErrors.canComplete, + onCompleteMessage = completedEventWithNoErrors.onCompleteMessage, + errorFields = emptyList(), + emptyMandatoryFields = emptyMap(), + warningFields = emptyList(), + eventMode = completedEventWithNoErrors.eventResultDetails.eventMode ?: EventMode.NEW, + eventState = completedEventWithNoErrors.eventResultDetails.eventStatus ?: EventStatus.ACTIVE, + result = completedEventWithNoErrors, + ) + assertTrue(noErrorsInFormModel.second.first().issueType == IssueType.WARNING_ON_COMPLETE) + } + + @Test + fun `Should configure to show error on complete message`() { + val completedEventWithNoErrors = SuccessfulResult( + canComplete = false, + onCompleteMessage = "error on complete", + eventResultDetails = EventResultDetails( + eventStatus = EventStatus.ACTIVE, + eventMode = EventMode.NEW, + validationStrategy = ValidationStrategy.ON_COMPLETE, + ), + ) + val noErrorsInFormModel = formResultDialogProvider.invoke( + canComplete = completedEventWithNoErrors.canComplete, + onCompleteMessage = completedEventWithNoErrors.onCompleteMessage, + errorFields = emptyList(), + emptyMandatoryFields = emptyMap(), + warningFields = emptyList(), + eventMode = completedEventWithNoErrors.eventResultDetails.eventMode ?: EventMode.NEW, + eventState = completedEventWithNoErrors.eventResultDetails.eventStatus ?: EventStatus.ACTIVE, + result = completedEventWithNoErrors, + ) + assertTrue(noErrorsInFormModel.second.first().issueType == IssueType.ERROR_ON_COMPLETE) + } + @Test fun `Should follow validation strategy when trying to save the form with errors`() { val completedEventWithNoErrors = SuccessfulResult(