hub-list-sort.test.mjs
39 lines 1.6 KB
Raw
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 14 hours ago
1 import { test } from 'node:test';
2 import assert from 'node:assert/strict';
3 import { sortNotesList, sortProposalsList } from '../web/hub/hub-list-sort.mjs';
4
5 test('sortNotesList date_desc and date_asc', () => {
6 const notes = [
7 { path: 'a.md', date: '2020-01-01', updated: null },
8 { path: 'b.md', date: '2022-06-01', updated: null },
9 { path: 'c.md', date: '2021-01-01', updated: null },
10 ];
11 const dk = (n) => n.date || '';
12 const d = sortNotesList(notes, 'date_desc', dk).map((n) => n.path);
13 assert.deepEqual(d, ['b.md', 'c.md', 'a.md']);
14 const asc = sortNotesList(notes, 'date_asc', dk).map((n) => n.path);
15 assert.deepEqual(asc, ['a.md', 'c.md', 'b.md']);
16 });
17
18 test('sortNotesList year_desc', () => {
19 const notes = [
20 { path: 'y1.md', date: '2019-12-31' },
21 { path: 'y2.md', date: '2022-01-01' },
22 { path: 'y3.md', date: '2022-06-01' },
23 ];
24 const dk = (n) => n.date || '';
25 const out = sortNotesList(notes, 'year_desc', dk).map((n) => n.path);
26 assert.deepEqual(out, ['y3.md', 'y2.md', 'y1.md']);
27 });
28
29 test('sortProposalsList updated_desc and status_asc', () => {
30 const list = [
31 { path: 'z.md', status: 'proposed', updated_at: '2024-01-02T00:00:00Z' },
32 { path: 'a.md', status: 'approved', updated_at: '2024-01-01T00:00:00Z' },
33 { path: 'm.md', status: 'discarded', updated_at: '2024-01-03T00:00:00Z' },
34 ];
35 const u = sortProposalsList(list, 'updated_desc').map((p) => p.path);
36 assert.deepEqual(u, ['m.md', 'z.md', 'a.md']);
37 const s = sortProposalsList(list, 'status_asc').map((p) => p.path);
38 assert.deepEqual(s, ['a.md', 'm.md', 'z.md']);
39 });
File History 1 commit
sha256:8915fe406161f95c1681f9469375e7bae5b28c884f00bedbdef65e4b0cd0738d docs(flow): commit FLOW-V0-SPEC.md hygiene for 7A-INT merge Human 14 hours ago