Skip to content

Commit

Permalink
Merge pull request #6107 from grzesiek2010/COLLECT-6017
Browse files Browse the repository at this point in the history
Fixed displaying saved forms to delete
  • Loading branch information
seadowg authored Apr 29, 2024
2 parents 3d2ca0b + 2d30b34 commit b3cd4a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,6 +40,7 @@ class SavedFormListViewModel(
}

val formsToDisplay: LiveData<List<Instance>> = instancesDataService.instances
.map { instances -> instances.filter { instance -> instance.deletedDate == null } }
.combine(_sortOrder) { instances, order ->
when (order) {
SortOrder.NAME_DESC -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -24,6 +25,7 @@ object InstanceFixtures {
it.formVersion(form.version)
}
}
.deletedDate(deletedDate)
.build()
}
}

0 comments on commit b3cd4a0

Please sign in to comment.