Skip to content

Commit a965652

Browse files
committed
feat: Support 'group by id' and 'group by id reverse'
1 parent 684c7bc commit a965652

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/Query/Filter/IdField.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ export class IdField extends TextField {
4848
public supportsSorting(): boolean {
4949
return true;
5050
}
51+
52+
// -----------------------------------------------------------------------------------------------------------------
53+
// Grouping
54+
// -----------------------------------------------------------------------------------------------------------------
55+
56+
public supportsGrouping(): boolean {
57+
return true;
58+
}
5159
}

tests/Query/Filter/IdField.test.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import {
77
expectTaskComparesEqual,
88
} from '../../CustomMatchers/CustomMatchersForSorting';
99

10-
describe('id', () => {
11-
const idField = new IdField();
10+
const idField = new IdField();
11+
12+
// Helper function to create a task with a given id
13+
function with_id(id: string) {
14+
return new TaskBuilder().id(id).build();
15+
}
1216

17+
describe('id', () => {
1318
it('should supply field name', () => {
1419
expect(idField.fieldName()).toEqual('id');
1520
});
@@ -81,11 +86,6 @@ describe('sorting by id', () => {
8186
expect(field.supportsSorting()).toEqual(true);
8287
});
8388

84-
// Helper function to create a task with a given id
85-
function with_id(id: string) {
86-
return new TaskBuilder().id(id).build();
87-
}
88-
8989
it('sort by id', () => {
9090
// Arrange
9191
const sorter = new IdField().createNormalSorter();
@@ -106,3 +106,16 @@ describe('sorting by id', () => {
106106
expectTaskComparesAfter(sorter, with_id('bbb'), with_id('ddd'));
107107
});
108108
});
109+
110+
describe('grouping by id', () => {
111+
// Only minimal tests needed, as TextField is well covered by other tests
112+
it('supports grouping methods correctly', () => {
113+
expect(idField).toSupportGroupingWithProperty('id');
114+
});
115+
116+
it('should group by id name', () => {
117+
const grouper = idField.createNormalGrouper();
118+
expect({ grouper, tasks: [with_id('')] }).groupHeadingsToBe([]);
119+
expect({ grouper, tasks: [with_id('rot7gb')] }).groupHeadingsToBe(['rot7gb']);
120+
});
121+
});

tests/Query/Query.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ describe('Query parsing', () => {
348348
'group by happens reverse',
349349
'group by heading',
350350
'group by heading reverse',
351+
'group by id',
352+
'group by id reverse',
351353
'group by path',
352354
'group by path reverse',
353355
'group by priority',

0 commit comments

Comments
 (0)