Skip to content

Commit

Permalink
Fixed displaying snackbar for autosend
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Jul 20, 2023
1 parent c2cddcd commit fbbc9bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 {
Expand Down

0 comments on commit fbbc9bb

Please sign in to comment.