diff --git a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/EncryptedFormTest.java b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/EncryptedFormTest.java index 0c313938cf4..9b7c7c79661 100644 --- a/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/EncryptedFormTest.java +++ b/collect_app/src/androidTest/java/org/odk/collect/android/feature/formentry/EncryptedFormTest.java @@ -88,4 +88,16 @@ public void instanceOfEncryptedFormWithoutInstanceID_failsFinalizationWithMessag .clickDrafts() .checkInstanceState("encrypted-no-instanceID", Instance.STATUS_INCOMPLETE); } + + @Test + public void instanceOfEncryptedFormWithoutInstanceID_doesNotLeaveSavepointOnFinalization() { + rule.startAtMainMenu() + .copyForm("encrypted-no-instanceID.xml") + .startBlankForm("encrypted-no-instanceID") + .clickGoToArrow() + .clickGoToEnd() + .clickFinalize() + .checkIsToastWithMessageDisplayed("This form does not specify an instanceID. You must specify one to enable encryption. Form has not been saved as finalized.") + .startBlankForm("encrypted-no-instanceID"); + } } diff --git a/collect_app/src/main/java/org/odk/collect/android/formentry/saving/FormSaveViewModel.java b/collect_app/src/main/java/org/odk/collect/android/formentry/saving/FormSaveViewModel.java index 88d50bdcc99..7b698702c6f 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formentry/saving/FormSaveViewModel.java +++ b/collect_app/src/main/java/org/odk/collect/android/formentry/saving/FormSaveViewModel.java @@ -2,6 +2,7 @@ import static org.odk.collect.android.tasks.SaveFormToDisk.SAVED; import static org.odk.collect.android.tasks.SaveFormToDisk.SAVED_AND_EXIT; +import static org.odk.collect.android.tasks.SaveFormToDisk.SAVE_ERROR; import static org.odk.collect.shared.strings.StringUtils.isBlank; import android.net.Uri; @@ -256,7 +257,7 @@ private void handleTaskResult(SaveToDiskResult taskResult, SaveRequest saveReque return; } - if (taskResult.getSaveResult() == SAVED || taskResult.getSaveResult() == SAVED_AND_EXIT) { + if (taskResult.getSaveResult() != SAVE_ERROR) { removeSavepoint(form.getDbId(), instance != null ? instance.getDbId() : null); } @@ -284,7 +285,7 @@ private void handleTaskResult(SaveToDiskResult taskResult, SaveRequest saveReque break; } - case SaveFormToDisk.SAVE_ERROR: { + case SAVE_ERROR: { formController.getAuditEventLogger().logEvent(AuditEvent.AuditEventType.SAVE_ERROR, true, clock.get()); saveResult.setValue(new SaveResult(SaveResult.State.SAVE_ERROR, saveRequest, taskResult.getSaveErrorMessage())); break;