Skip to content

Commit

Permalink
Merge pull request #5415 from grzesiek2010/COLLECT-5413
Browse files Browse the repository at this point in the history
Fixed sorting by date
  • Loading branch information
grzesiek2010 authored and seadowg committed Jan 25, 2023
1 parent 4fafd51 commit 97a5566
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ class BlankFormListViewModel(
_formsToDisplay.value = when (sortingOrder) {
0 -> _allForms.value.sortedBy { it.formName.lowercase() }
1 -> _allForms.value.sortedByDescending { it.formName.lowercase() }
2 -> _allForms.value.sortedByDescending { it.dateOfCreation }
3 -> _allForms.value.sortedBy { it.dateOfCreation }
2 -> _allForms.value.sortedByDescending { it.dateOfLastDetectedAttachmentsUpdate ?: it.dateOfCreation }
3 -> _allForms.value.sortedBy { it.dateOfLastDetectedAttachmentsUpdate ?: it.dateOfCreation }
4 -> _allForms.value.sortedByDescending { it.dateOfLastUsage }
else -> { _allForms.value }
}.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,30 +283,30 @@ class BlankFormListViewModelTest {
fun `when list of forms sorted 'by date newest first', saved should forms be ordered properly`() {
saveForms(
form(dbId = 1, formId = "1", formName = "1Form"),
form(dbId = 2, formId = "2", formName = "BForm"),
form(dbId = 2, formId = "2", formName = "BForm", lastDetectedAttachmentsUpdateDate = 6),
form(dbId = 3, formId = "3", formName = "aForm"),
form(dbId = 4, formId = "4", formName = "AForm"),
form(dbId = 4, formId = "4", formName = "AForm", lastDetectedAttachmentsUpdateDate = 7),
form(dbId = 5, formId = "5", formName = "2Form")
)

createViewModel()

viewModel.sortingOrder = 2

assertFormItem(viewModel.formsToDisplay.value!![0], form(dbId = 5, formId = "5", formName = "2Form"))
assertFormItem(viewModel.formsToDisplay.value!![1], form(dbId = 4, formId = "4", formName = "AForm"))
assertFormItem(viewModel.formsToDisplay.value!![2], form(dbId = 3, formId = "3", formName = "aForm"))
assertFormItem(viewModel.formsToDisplay.value!![3], form(dbId = 2, formId = "2", formName = "BForm"))
assertFormItem(viewModel.formsToDisplay.value!![0], form(dbId = 4, formId = "4", formName = "AForm", lastDetectedAttachmentsUpdateDate = 7))
assertFormItem(viewModel.formsToDisplay.value!![1], form(dbId = 2, formId = "2", formName = "BForm", lastDetectedAttachmentsUpdateDate = 6))
assertFormItem(viewModel.formsToDisplay.value!![2], form(dbId = 5, formId = "5", formName = "2Form"))
assertFormItem(viewModel.formsToDisplay.value!![3], form(dbId = 3, formId = "3", formName = "aForm"))
assertFormItem(viewModel.formsToDisplay.value!![4], form(dbId = 1, formId = "1", formName = "1Form"))
}

@Test
fun `when list of forms sorted 'by date oldest first', saved should forms be ordered properly`() {
saveForms(
form(dbId = 1, formId = "1", formName = "1Form"),
form(dbId = 2, formId = "2", formName = "BForm"),
form(dbId = 2, formId = "2", formName = "BForm", lastDetectedAttachmentsUpdateDate = 6),
form(dbId = 3, formId = "3", formName = "aForm"),
form(dbId = 4, formId = "4", formName = "AForm"),
form(dbId = 4, formId = "4", formName = "AForm", lastDetectedAttachmentsUpdateDate = 7),
form(dbId = 5, formId = "5", formName = "2Form")
)

Expand All @@ -315,10 +315,10 @@ class BlankFormListViewModelTest {
viewModel.sortingOrder = 3

assertFormItem(viewModel.formsToDisplay.value!![0], form(dbId = 1, formId = "1", formName = "1Form"))
assertFormItem(viewModel.formsToDisplay.value!![1], form(dbId = 2, formId = "2", formName = "BForm"))
assertFormItem(viewModel.formsToDisplay.value!![2], form(dbId = 3, formId = "3", formName = "aForm"))
assertFormItem(viewModel.formsToDisplay.value!![3], form(dbId = 4, formId = "4", formName = "AForm"))
assertFormItem(viewModel.formsToDisplay.value!![4], form(dbId = 5, formId = "5", formName = "2Form"))
assertFormItem(viewModel.formsToDisplay.value!![1], form(dbId = 3, formId = "3", formName = "aForm"))
assertFormItem(viewModel.formsToDisplay.value!![2], form(dbId = 5, formId = "5", formName = "2Form"))
assertFormItem(viewModel.formsToDisplay.value!![3], form(dbId = 2, formId = "2", formName = "BForm", lastDetectedAttachmentsUpdateDate = 6))
assertFormItem(viewModel.formsToDisplay.value!![4], form(dbId = 4, formId = "4", formName = "AForm", lastDetectedAttachmentsUpdateDate = 7))
}

@Test
Expand Down Expand Up @@ -540,7 +540,8 @@ class BlankFormListViewModelTest {
formId: String = "1",
version: String? = null,
formName: String = "Form $formId",
deleted: Boolean = false
deleted: Boolean = false,
lastDetectedAttachmentsUpdateDate: Long? = null
) = Form.Builder()
.dbId(dbId)
.formId(formId)
Expand All @@ -549,6 +550,7 @@ class BlankFormListViewModelTest {
.date(dbId)
.deleted(deleted)
.formFilePath(FormUtils.createXFormFile(formId, version).absolutePath)
.lastDetectedAttachmentsUpdateDate(lastDetectedAttachmentsUpdateDate)
.build()

private fun instance(
Expand Down

0 comments on commit 97a5566

Please sign in to comment.