Skip to content

Commit

Permalink
test: - Add more tests for RandomField
Browse files Browse the repository at this point in the history
  • Loading branch information
claremacrae committed Oct 5, 2024
1 parent acd96b5 commit 6bd5130
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/Query/Filter/RandomField.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ import moment from 'moment';
import { RandomField } from '../../../src/Query/Filter/RandomField';
import { fromLine } from '../../TestingTools/TestHelpers';
import { expectTaskComparesEqual } from '../../CustomMatchers/CustomMatchersForSorting';
import { TaskBuilder } from '../../TestingTools/TaskBuilder';

window.moment = moment;

const field = new RandomField();

beforeAll(() => {
jest.useFakeTimers();
jest.setSystemTime(new Date('2024-01-23'));
});

afterAll(() => {
jest.useRealTimers();
});

describe('filtering by random', () => {
it('should be named random', () => {
expect(field.fieldName()).toEqual('random');
Expand All @@ -30,6 +40,36 @@ describe('sorting by random', () => {
// Assert
expectTaskComparesEqual(sorter, task1, task1);
});

it('sort key should ignore task properties except description', () => {
const fullyPopulatedTask = TaskBuilder.createFullyPopulatedTask();
const taskWithSameDescription = new TaskBuilder().description(fullyPopulatedTask.description).build();
expect(field.sortKey(fullyPopulatedTask)).toEqual(field.sortKey(taskWithSameDescription));
});

it('sort key should not change, at different times', () => {
const task1 = fromLine({ line: '- [ ] My sort key should be same, regardless of time' });

jest.setSystemTime(new Date('2024-10-19 10:42'));
const sortKeyAtTime1 = field.sortKey(task1);

jest.setSystemTime(new Date('2024-10-19 21:05'));
const sortKeyAtTime2 = field.sortKey(task1);

expect(sortKeyAtTime1).toEqual(sortKeyAtTime2);
});

it('sort key should change on different dates', () => {
const task1 = fromLine({ line: '- [ ] My sort key should differ on different dates' });

jest.setSystemTime(new Date('2024-01-23'));
const sortKeyOnDay1 = field.sortKey(task1);

jest.setSystemTime(new Date('2024-01-24'));
const sortKeyOnDay2 = field.sortKey(task1);

expect(sortKeyOnDay1).not.toEqual(sortKeyOnDay2);
});
});

describe('grouping by random', () => {
Expand Down

0 comments on commit 6bd5130

Please sign in to comment.