diff options
| -rw-r--r-- | web/app.js | 18 | ||||
| -rw-r--r-- | web/test/tab-persistence.test.mjs | 8 | ||||
| -rw-r--r-- | web/test/tasks-board.test.mjs | 19 |
3 files changed, 32 insertions, 13 deletions
@@ -3377,16 +3377,17 @@ export function columnForTaskState(state) { // interrupted — newest-first (most recent failure is most urgent) // done — newest-first (most recently completed is most relevant) // running — newest-first (new-but-inconsequential default) -const TASK_COLUMN_SORT = { - queue: (a, b) => new Date(a.created_at || 0) - new Date(b.created_at || 0), - running: (a, b) => new Date(b.created_at || 0) - new Date(a.created_at || 0), - ready: (a, b) => new Date(a.created_at || 0) - new Date(b.created_at || 0), - interrupted: (a, b) => new Date(b.created_at || 0) - new Date(a.created_at || 0), - done: (a, b) => new Date(b.created_at || 0) - new Date(a.created_at || 0), +// Tasks with a missing created_at sort LAST in any direction (per sortTasksByDate). +const TASK_COLUMN_DESCEND = { + queue: false, + running: true, + ready: false, + interrupted: true, + done: true, }; // groupTasksByColumn returns { [columnKey]: task[] }, each sub-array sorted -// per the per-column sort direction above. +// per the per-column sort direction above via the shared sortTasksByDate helper. export function groupTasksByColumn(tasks) { const groups = {}; for (const col of TASK_COLUMNS) groups[col.key] = []; @@ -3396,8 +3397,7 @@ export function groupTasksByColumn(tasks) { groups[key].push(t); } for (const col of TASK_COLUMNS) { - const cmp = TASK_COLUMN_SORT[col.key]; - if (cmp) groups[col.key].sort(cmp); + groups[col.key] = sortTasksByDate(groups[col.key], TASK_COLUMN_DESCEND[col.key] ?? false); } return groups; } diff --git a/web/test/tab-persistence.test.mjs b/web/test/tab-persistence.test.mjs index 972723c..9311453 100644 --- a/web/test/tab-persistence.test.mjs +++ b/web/test/tab-persistence.test.mjs @@ -20,8 +20,8 @@ import { getActiveMainTab, setActiveMainTab } from '../app.js'; describe('getActiveMainTab', () => { beforeEach(() => store.clear()); - it('returns "stories" when localStorage has no stored value', () => { - assert.equal(getActiveMainTab(), 'stories'); + it('returns "queue" when localStorage has no stored value', () => { + assert.equal(getActiveMainTab(), 'queue'); }); it('returns the tab name stored by setActiveMainTab', () => { @@ -29,10 +29,10 @@ describe('getActiveMainTab', () => { assert.equal(getActiveMainTab(), 'settings'); }); - it('returns "stories" after localStorage value is removed', () => { + it('returns "queue" after localStorage value is removed', () => { setActiveMainTab('stats'); localStorage.removeItem('activeMainTab'); - assert.equal(getActiveMainTab(), 'stories'); + assert.equal(getActiveMainTab(), 'queue'); }); it('reflects the most recent setActiveMainTab call', () => { diff --git a/web/test/tasks-board.test.mjs b/web/test/tasks-board.test.mjs index 85bb04a..560e8c8 100644 --- a/web/test/tasks-board.test.mjs +++ b/web/test/tasks-board.test.mjs @@ -42,6 +42,7 @@ describe('columnForTaskState', () => { ]) { assert.ok(allStates.includes(s), `${s} missing from any column`); } + assert.equal(new Set(allStates).size, allStates.length, 'a state must map to exactly one column'); }); }); @@ -120,6 +121,24 @@ describe('groupTasksByColumn', () => { assert.deepEqual(groups.running.map(t => t.id), ['newer', 'older']); }); + it('sorts a task with no created_at LAST in an ascending column (queue)', () => { + const tasks = [ + { id: 'no-date', state: 'PENDING' }, + { id: 'has-date', state: 'QUEUED', created_at: '2024-01-01T00:00:00Z' }, + ]; + const groups = groupTasksByColumn(tasks); + assert.deepEqual(groups.queue.map(t => t.id), ['has-date', 'no-date']); + }); + + it('sorts a task with no created_at LAST in a descending column (interrupted)', () => { + const tasks = [ + { id: 'no-date', state: 'FAILED' }, + { id: 'has-date', state: 'CANCELLED', created_at: '2024-01-01T00:00:00Z' }, + ]; + const groups = groupTasksByColumn(tasks); + assert.deepEqual(groups.interrupted.map(t => t.id), ['has-date', 'no-date']); + }); + it('handles null/undefined gracefully', () => { const groups = groupTasksByColumn(null); for (const col of TASK_COLUMNS) { |
