Skip to content

Commit

Permalink
Merge pull request #371 from nextcloud/fix-sort
Browse files Browse the repository at this point in the history
Fix the task sorting
  • Loading branch information
raimund-schluessler committed Apr 22, 2019
2 parents fa6b887 + 6cd41ac commit a41527d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"jsdom": "^15.0.0",
"jsdom-global": "^3.0.2",
"node-sass": "^4.11.0",
"moment": "^2.24.0",
"prettier-eslint": "^8.8.2",
"raw-loader": "^2.0.0",
"sass-loader": "^7.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/SortorderDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default {
id: 'default',
icon: 'icon-list',
text: t('tasks', 'Default'),
hint: t('tasks', 'Sort by completed state, priority, start date and summary.')
hint: t('tasks', 'Sort by completed state, due date, priority, start date and summary.')
},
{
id: 'due',
Expand Down
6 changes: 3 additions & 3 deletions src/store/storeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function sort(tasks, sortOrder, sortDirection) {
break
}
default:
comparators = [sortByCompleted, sortByPriority, sortByStart, sortAlphabetically]
comparators = [sortByCompleted, sortByDue, sortByPriority, sortByStart, sortAlphabetically]
}
var sortedTasks = tasks.sort((taskA, taskB) => {
var compIndex = 0
Expand Down Expand Up @@ -272,11 +272,11 @@ function sortByCreated(taskA, taskB) {
*/
function sortByDate(taskA, taskB, date) {
if (taskA[date] === null && taskB[date] !== null) {
return -1
return 1
}

if (taskA[date] !== null && taskB[date] === null) {
return 1
return -1
}

if (taskA[date] === null && taskB[date] === null) {
Expand Down
41 changes: 41 additions & 0 deletions tests/store/storeHelper.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import moment from 'moment'
import { sort } from '@/store/storeHelper'

global.moment = moment

const tasks = [
{
id: 1,
due: '20191119T183901'
},
{
id: 2,
due: '20181119T183901'
},
{
id: 3,
due: null
},
{
id: 4,
due: '20151119T183901'
},
]

describe('storeHelper', () => {
'use strict'

it('Tests descending sort by due date.', () => {
const clonedTasks = tasks.slice(0)
const expectedTasks = [tasks[3], tasks[1], tasks[0], tasks[2]]
const receivedTasks = sort(clonedTasks, 'due', 0)
expect(receivedTasks).toEqual(expectedTasks)
})

it('Tests ascending sort by due date.', () => {
const clonedTasks = tasks.slice(0)
const expectedTasks = [tasks[2], tasks[0], tasks[1], tasks[3]]
const receivedTasks = sort(clonedTasks, 'due', 1)
expect(receivedTasks).toEqual(expectedTasks)
})
})

0 comments on commit a41527d

Please sign in to comment.