Skip to content

Commit 0646263

Browse files
committed
test: - Add failing test of sorting floating points of differing precision
See #3371
1 parent 691baa4 commit 0646263

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

tests/Query/Group/TaskGroups.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ import { StatusTypeField } from '../../../src/Query/Filter/StatusTypeField';
1313
import { HappensDateField } from '../../../src/Query/Filter/HappensDateField';
1414
import { DueDateField } from '../../../src/Query/Filter/DueDateField';
1515
import { SearchInfo } from '../../../src/Query/SearchInfo';
16-
import { fromLine } from '../../TestingTools/TestHelpers';
16+
import { fromLine, fromLines } from '../../TestingTools/TestHelpers';
1717
import { TaskBuilder } from '../../TestingTools/TaskBuilder';
1818
import { TasksFile } from '../../../src/Scripting/TasksFile';
19+
import { FunctionField } from '../../../src/Query/Filter/FunctionField';
20+
import type { TaskGroup } from '../../../src/Query/Group/TaskGroup';
1921

2022
window.moment = moment;
2123

22-
function makeTasksGroups(grouping: Grouper[], inputs: Task[]): any {
24+
function makeTasksGroups(grouping: Grouper[], inputs: Task[]): TaskGroups {
2325
return new TaskGroups(grouping, inputs, SearchInfo.fromAllTasks(inputs));
2426
}
2527

28+
beforeEach(() => {});
29+
30+
afterEach(() => {
31+
jest.useRealTimers();
32+
});
2633
describe('Grouping tasks', () => {
2734
it('groups correctly by path', () => {
2835
// Arrange
@@ -231,6 +238,30 @@ describe('Grouping tasks', () => {
231238
`);
232239
});
233240

241+
it.failing('sorts raw urgency value groups correctly', () => {
242+
jest.useFakeTimers();
243+
jest.setSystemTime(new Date('2025-03-07'));
244+
245+
const lines = [
246+
'- [ ] 1 📅 2025-03-07 ⏳ 2025-03-07', // urgency: 15.75
247+
'- [ ] 2 📅 2025-03-08 ⏳ 2025-03-07', // urgency: 15.292857142857141
248+
'- [ ] 3 📅 2025-03-09 ⏳ 2025-03-07', // urgency: 14.835714285714285
249+
];
250+
const tasks = fromLines({ lines });
251+
252+
// See issue https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3371
253+
// order of groups, when grouping by "function task.urgency" without specifying precision, is confusing
254+
// There is a problem with the sorting of groups whose floating-point values differ in precision,
255+
// when grouping by the raw urgency value
256+
const grouping = [new FunctionField().createGrouperFromLine('group by function task.urgency')!];
257+
258+
const groups: TaskGroups = makeTasksGroups(grouping, tasks);
259+
const groupHeadings = groups.groups.map((group: TaskGroup) => group.groups[0].slice(0, 7));
260+
261+
expect(groupHeadings).toEqual(['14.8357', '15.75', '15.2928']); // This passes: it shows that the order is illogical (non-ascending).
262+
expect(groupHeadings).toEqual(['14.8357', '15.2928', '15.75']); // This fails: it is what users would expect.
263+
});
264+
234265
it('handles tasks matching multiple groups correctly', () => {
235266
const a = fromLine({
236267
line: '- [ ] Task 1 #group1',

0 commit comments

Comments
 (0)