Repository navigation
Expand file tree
/
Copy pathsession-grouper.test.js
More file actions
146 lines (134 loc) · 5.66 KB
/
Copy pathsession-grouper.test.js
File metadata and controls
146 lines (134 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const { describe, it } = require('node:test');
const assert = require('node:assert');
const { groupSessions } = require('./session-grouper');
describe('session-grouper', () => {
it('returns empty array for empty sessions', () => {
const result = groupSessions([]);
assert.deepStrictEqual(result, []);
});
it('places today sessions in Today group', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-05-12T10:00:00.000Z', title: 'A' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].name, 'Today');
assert.strictEqual(result[0].sessions.length, 1);
assert.strictEqual(result[0].sessions[0].id, 's1');
assert.strictEqual(result[0].expanded, true);
});
it('places yesterday sessions in Yesterday group', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-05-11T10:00:00.000Z', title: 'A' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].name, 'Yesterday');
assert.strictEqual(result[0].expanded, true);
});
it('places this-week sessions in This Week group', () => {
// 2026-05-12 is a Tuesday in UTC
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-05-10T10:00:00.000Z', title: 'Sunday' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].name, 'This Week');
assert.strictEqual(result[0].sessions.length, 1);
assert.strictEqual(result[0].sessions[0].id, 's1');
assert.strictEqual(result[0].expanded, false);
});
it('groups earlier sessions by month', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-04-20T10:00:00.000Z', title: 'April' },
{ id: 's2', modified: '2026-03-15T10:00:00.000Z', title: 'March' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 2);
assert.strictEqual(result[0].name, 'April 2026');
assert.strictEqual(result[0].sessions.length, 1);
assert.strictEqual(result[1].name, 'March 2026');
assert.strictEqual(result[1].sessions.length, 1);
assert.strictEqual(result[1].expanded, false);
});
it('sorts month groups descending by date', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-03-15T10:00:00.000Z', title: 'March' },
{ id: 's2', modified: '2026-04-20T10:00:00.000Z', title: 'April' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result[0].name, 'April 2026');
assert.strictEqual(result[1].name, 'March 2026');
});
it('handles all buckets simultaneously', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-05-12T10:00:00.000Z', title: 'Today' },
{ id: 's2', modified: '2026-05-11T10:00:00.000Z', title: 'Yesterday' },
{ id: 's3', modified: '2026-05-10T10:00:00.000Z', title: 'Sunday' },
{ id: 's4', modified: '2026-04-20T10:00:00.000Z', title: 'April' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 4);
assert.strictEqual(result[0].name, 'Today');
assert.strictEqual(result[1].name, 'Yesterday');
assert.strictEqual(result[2].name, 'This Week');
assert.strictEqual(result[3].name, 'April 2026');
});
it('respects custom expandedGroups config', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-05-12T10:00:00.000Z', title: 'A' },
{ id: 's2', modified: '2026-05-11T10:00:00.000Z', title: 'B' }
];
const result = groupSessions(sessions, { now, expandedGroups: ['Today'] });
assert.strictEqual(result[0].expanded, true);
assert.strictEqual(result[1].expanded, false);
});
it('omits empty groups', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-04-20T10:00:00.000Z', title: 'April' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].name, 'April 2026');
});
it('handles year boundaries correctly', () => {
const now = '2026-01-02T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2025-12-31T10:00:00.000Z', title: 'Last Year' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].name, 'This Week');
});
it('handles Sunday as start of week boundary', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-05-10T10:00:00.000Z', title: 'Sunday' },
{ id: 's2', modified: '2026-05-09T10:00:00.000Z', title: 'Saturday' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 2);
assert.strictEqual(result[0].name, 'This Week');
assert.strictEqual(result[0].sessions[0].id, 's1');
assert.strictEqual(result[1].name, 'May 2026');
assert.strictEqual(result[1].sessions[0].id, 's2');
});
it('groups multiple sessions in same month', () => {
const now = '2026-05-12T12:00:00.000Z';
const sessions = [
{ id: 's1', modified: '2026-04-01T10:00:00.000Z', title: 'A' },
{ id: 's2', modified: '2026-04-20T10:00:00.000Z', title: 'B' }
];
const result = groupSessions(sessions, { now });
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].sessions.length, 2);
});
});