mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 10:44:23 +00:00
feat(todo): sort the task list by due date (#2205)
The list held its manual order, so an item due tomorrow sat behind one created earlier but due later. The sort-by section gains a due-date toggle next to the priority one, on desktop and in the phone tab: nearest deadline first, undated tasks after all dated ones, ties keep the manual order. One sort at a time, and manual drag-reorder pauses while either is active, exactly like the priority sort.
This commit is contained in:
@@ -181,6 +181,27 @@ describe('MTodoListTab', () => {
|
||||
expect(rowOrder(['Low', 'High'])).toEqual(['High', 'Low'])
|
||||
})
|
||||
|
||||
it('FE-MOB-TODO-020: toggles the due-date sort and puts the nearest deadline first (#2205)', () => {
|
||||
setup([
|
||||
todo({ id: 1, name: 'Later', due_date: '2099-07-17' }),
|
||||
todo({ id: 2, name: 'Sooner', due_date: '2099-07-16' }),
|
||||
todo({ id: 3, name: 'Undated' }),
|
||||
])
|
||||
|
||||
expect(rowOrder(['Later', 'Sooner', 'Undated'])).toEqual(['Later', 'Sooner', 'Undated'])
|
||||
|
||||
const sortButton = screen.getByRole('button', { name: /todo.detail.dueDate/ })
|
||||
expect(sortButton).toHaveAttribute('aria-pressed', 'false')
|
||||
fireEvent.click(sortButton)
|
||||
|
||||
expect(sortButton).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(rowOrder(['Later', 'Sooner', 'Undated'])).toEqual(['Sooner', 'Later', 'Undated'])
|
||||
|
||||
// one sort at a time: flipping priority on releases the due toggle
|
||||
fireEvent.click(screen.getByRole('button', { name: /todo.priority/ }))
|
||||
expect(sortButton).toHaveAttribute('aria-pressed', 'false')
|
||||
})
|
||||
|
||||
it('FE-MOB-TODO-009: floats overdue rows above the other open ones', () => {
|
||||
setup([
|
||||
todo({ id: 1, name: 'Open' }),
|
||||
|
||||
@@ -23,7 +23,7 @@ import { STATUS_COLOR } from '../../../../src/mobile/screens/trip/tabs/tabModel'
|
||||
import { PACKING_PLACEHOLDER_NAME } from '../../../../src/components/Packing/packingListPanel.constants';
|
||||
import { buildPackingItem, buildTodoItem } from '../../../helpers/factories';
|
||||
|
||||
// FE-MOB-LSTM-001 to FE-MOB-LSTM-020
|
||||
// FE-MOB-LSTM-001 to FE-MOB-LSTM-021
|
||||
|
||||
const TODAY = '2026-07-15';
|
||||
|
||||
@@ -160,7 +160,7 @@ describe('listsModel — to-do', () => {
|
||||
});
|
||||
|
||||
it('FE-MOB-LSTM-014: sortTodoRows floats overdue rows up and sinks done rows', () => {
|
||||
const sorted = sortTodoRows(items, false, TODAY);
|
||||
const sorted = sortTodoRows(items, null, TODAY);
|
||||
expect(sorted.map(i => i.id)).toEqual([3, 1, 2, 4]);
|
||||
// the input array stays untouched
|
||||
expect(items.map(i => i.id)).toEqual([1, 2, 3, 4]);
|
||||
@@ -172,8 +172,19 @@ describe('listsModel — to-do', () => {
|
||||
const none = buildTodoItem({ id: 12, priority: 0 });
|
||||
const list = [p3, none, p1];
|
||||
|
||||
expect(sortTodoRows(list, false, TODAY).map(i => i.id)).toEqual([10, 12, 11]);
|
||||
expect(sortTodoRows(list, true, TODAY).map(i => i.id)).toEqual([11, 10, 12]);
|
||||
expect(sortTodoRows(list, null, TODAY).map(i => i.id)).toEqual([10, 12, 11]);
|
||||
expect(sortTodoRows(list, 'priority', TODAY).map(i => i.id)).toEqual([11, 10, 12]);
|
||||
});
|
||||
|
||||
it('FE-MOB-LSTM-021: sortTodoRows orders by nearest due date, undated last, creation order untouched otherwise (#2205)', () => {
|
||||
const inTwoDays = buildTodoItem({ id: 20, due_date: '2026-07-17' });
|
||||
const tomorrow = buildTodoItem({ id: 21, due_date: '2026-07-16' });
|
||||
const undated = buildTodoItem({ id: 22 });
|
||||
const list = [inTwoDays, undated, tomorrow];
|
||||
|
||||
// the issue's literal repro: created first, due later, must sort behind
|
||||
expect(sortTodoRows(list, 'due', TODAY).map(i => i.id)).toEqual([21, 20, 22]);
|
||||
expect(sortTodoRows(list, null, TODAY).map(i => i.id)).toEqual([20, 22, 21]);
|
||||
});
|
||||
|
||||
it('FE-MOB-LSTM-016: todoCategories returns distinct categories alphabetically', () => {
|
||||
|
||||
Reference in New Issue
Block a user