mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 09:45:04 -05:00
Make text, member, label and date headers toggle a shared client-side ascending or descending comparator. Keep empty date values last and use card title as a deterministic tie-breaker. Add comparator boundary coverage and a browser header-toggle regression. Thanks to rmb82 and xet7 ! Fixes #6633,
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
compareTableViewRows,
|
|
nextTableViewSort,
|
|
} = require('../models/lib/tableViewSort');
|
|
|
|
const rows = [
|
|
{ title: 'Card 10', listTitle: 'Beta', dueAt: null },
|
|
{ title: 'Card 2', listTitle: 'Alpha', dueAt: new Date('2026-09-02') },
|
|
{ title: 'Card 1', listTitle: 'Alpha', dueAt: new Date('2026-09-01') },
|
|
];
|
|
const sorted = (field, direction) =>
|
|
rows.slice().sort((a, b) => compareTableViewRows(a, b, field, direction));
|
|
|
|
assert.deepStrictEqual(sorted('title', 'asc').map(row => row.title), [
|
|
'Card 1',
|
|
'Card 2',
|
|
'Card 10',
|
|
]);
|
|
assert.deepStrictEqual(sorted('title', 'desc').map(row => row.title), [
|
|
'Card 10',
|
|
'Card 2',
|
|
'Card 1',
|
|
]);
|
|
assert.deepStrictEqual(sorted('listTitle', 'asc').map(row => row.title), [
|
|
'Card 1',
|
|
'Card 2',
|
|
'Card 10',
|
|
]);
|
|
assert.deepStrictEqual(sorted('dueAt', 'desc').map(row => row.title), [
|
|
'Card 2',
|
|
'Card 1',
|
|
'Card 10',
|
|
]);
|
|
assert.deepStrictEqual(nextTableViewSort('title', 'asc', 'title'), {
|
|
field: 'title',
|
|
direction: 'desc',
|
|
});
|
|
assert.deepStrictEqual(nextTableViewSort('title', 'desc', 'dueAt'), {
|
|
field: 'dueAt',
|
|
direction: 'asc',
|
|
});
|
|
|
|
console.log('tableViewSort: 6 checks passed');
|