From fbbc9bb8eb0b15a0556f73eb733ab584ba9c420a Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Thu, 20 Jul 2023 16:19:11 +0200 Subject: [PATCH] Fixed displaying snackbar for autosend --- .../org/odk/collect/android/mainmenu/MainMenuViewModel.kt | 2 +- .../odk/collect/android/mainmenu/MainMenuViewModelTest.kt | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/mainmenu/MainMenuViewModel.kt b/collect_app/src/main/java/org/odk/collect/android/mainmenu/MainMenuViewModel.kt index bcd53ae0d39..c22de8adaee 100644 --- a/collect_app/src/main/java/org/odk/collect/android/mainmenu/MainMenuViewModel.kt +++ b/collect_app/src/main/java/org/odk/collect/android/mainmenu/MainMenuViewModel.kt @@ -111,7 +111,7 @@ class MainMenuViewModel( return if (instance != null) { val message = if (instance.status == Instance.STATUS_INCOMPLETE) { R.string.form_saved_as_draft - } else if (instance.status == Instance.STATUS_COMPLETE) { + } else if (instance.status == Instance.STATUS_COMPLETE || instance.status == Instance.STATUS_SUBMISSION_FAILED) { val form = formsRepositoryProvider.get().getAllByFormIdAndVersion(instance.formId, instance.formVersion).first() if (form.shouldFormBeSentAutomatically(autoSendSettingsProvider.isAutoSendEnabledInSettings())) { R.string.form_sending diff --git a/collect_app/src/test/java/org/odk/collect/android/mainmenu/MainMenuViewModelTest.kt b/collect_app/src/test/java/org/odk/collect/android/mainmenu/MainMenuViewModelTest.kt index 1b94ae7bafc..d2dd6a32e99 100644 --- a/collect_app/src/test/java/org/odk/collect/android/mainmenu/MainMenuViewModelTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/mainmenu/MainMenuViewModelTest.kt @@ -291,7 +291,7 @@ class MainMenuViewModelTest { } @Test - fun `getFormSavedSnackbarDetails should return null when the corresponding instance failed to sent`() { + fun `getFormSavedSnackbarDetails should return proper message and action when the corresponding instance failed to sent`() { val viewModel = createViewModelWithVersion("") formsRepository.save(FormUtils.buildForm("1", "1", TempFiles.createTempDir().absolutePath).build()) @@ -307,8 +307,9 @@ class MainMenuViewModelTest { whenever(autoSendSettingsProvider.isAutoSendEnabledInSettings()).thenReturn(true) val uri = InstancesContract.getUri(Project.DEMO_PROJECT_ID, instance.dbId) - val formSavedSnackbarDetails = viewModel.getFormSavedSnackbarDetails(uri) - assertThat(formSavedSnackbarDetails, equalTo(null)) + val formSavedSnackbarDetails = viewModel.getFormSavedSnackbarDetails(uri)!! + assertThat(formSavedSnackbarDetails.first, equalTo(R.string.form_sending)) + assertThat(formSavedSnackbarDetails.second, equalTo(R.string.view_form)) } private fun createViewModelWithVersion(version: String): MainMenuViewModel {