From db7ade0027b20e3dda28b912ea0a5f3e40d9e517 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Sun, 28 Apr 2024 18:47:57 +0200 Subject: [PATCH 1/2] Added a failing test --- .../savedformlist/SavedFormListViewModelTest.kt | 14 ++++++++++++++ .../org/odk/collect/formstest/InstanceFixtures.kt | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/collect_app/src/test/java/org/odk/collect/android/formlists/savedformlist/SavedFormListViewModelTest.kt b/collect_app/src/test/java/org/odk/collect/android/formlists/savedformlist/SavedFormListViewModelTest.kt index 4f30467de42..7814ee1ec8c 100644 --- a/collect_app/src/test/java/org/odk/collect/android/formlists/savedformlist/SavedFormListViewModelTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/formlists/savedformlist/SavedFormListViewModelTest.kt @@ -34,6 +34,20 @@ class SavedFormListViewModelTest { on { instances } doReturn MutableStateFlow(emptyList()) } + @Test + fun `formsToDisplay should not include deleted forms`() { + val myForm = InstanceFixtures.instance(displayName = "My form", deletedDate = 1) + val yourForm = InstanceFixtures.instance(displayName = "Your form") + saveForms(listOf(myForm, yourForm)) + + val viewModel = SavedFormListViewModel(scheduler, settings, instancesDataService, "projectId") + + assertThat( + viewModel.formsToDisplay.getOrAwaitValue(scheduler), + contains(yourForm) + ) + } + @Test fun `setting filterText filters forms on display name`() { val myForm = InstanceFixtures.instance(displayName = "My form") diff --git a/forms-test/src/main/java/org/odk/collect/formstest/InstanceFixtures.kt b/forms-test/src/main/java/org/odk/collect/formstest/InstanceFixtures.kt index 00158df29c0..d21991db344 100644 --- a/forms-test/src/main/java/org/odk/collect/formstest/InstanceFixtures.kt +++ b/forms-test/src/main/java/org/odk/collect/formstest/InstanceFixtures.kt @@ -11,7 +11,8 @@ object InstanceFixtures { lastStatusChangeDate: Long = 0, displayName: String? = null, dbId: Long? = null, - form: Form? = null + form: Form? = null, + deletedDate: Long? = null ): Instance { val instancesDir = TempFiles.createTempDir() return InstanceUtils.buildInstance("formId", "version", instancesDir.absolutePath) @@ -24,6 +25,7 @@ object InstanceFixtures { it.formVersion(form.version) } } + .deletedDate(deletedDate) .build() } } From 2d30b34b6bb765ec63046456e172bf26f780ccb4 Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 24 Apr 2024 09:43:12 +0200 Subject: [PATCH 2/2] Filter instances in DeleteSavedFormListViewModel --- .../android/formlists/savedformlist/SavedFormListViewModel.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/collect_app/src/main/java/org/odk/collect/android/formlists/savedformlist/SavedFormListViewModel.kt b/collect_app/src/main/java/org/odk/collect/android/formlists/savedformlist/SavedFormListViewModel.kt index e36dbaba1df..f9b826e329c 100644 --- a/collect_app/src/main/java/org/odk/collect/android/formlists/savedformlist/SavedFormListViewModel.kt +++ b/collect_app/src/main/java/org/odk/collect/android/formlists/savedformlist/SavedFormListViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.asLiveData import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.map import org.odk.collect.android.instancemanagement.InstancesDataService import org.odk.collect.androidshared.async.TrackableWorker import org.odk.collect.androidshared.data.Consumable @@ -39,6 +40,7 @@ class SavedFormListViewModel( } val formsToDisplay: LiveData> = instancesDataService.instances + .map { instances -> instances.filter { instance -> instance.deletedDate == null } } .combine(_sortOrder) { instances, order -> when (order) { SortOrder.NAME_DESC -> {