Skip to content

Commit

Permalink
test: Add tests for repeating task with +1d and +1h repeaters
Browse files Browse the repository at this point in the history
  • Loading branch information
munen committed Nov 9, 2021
1 parent 2cf10c2 commit 94ef624
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/reducers/org.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ describe('org reducer', () => {
state.org.present = state.org.present
.setIn(['files', path], parseOrg(contents))
.set('path', path);
state.base = state.base.set('shouldLogIntoDrawer', true);

return state;
}

Expand Down Expand Up @@ -822,6 +824,8 @@ describe('org reducer', () => {
let doneHeaderId;
let repeatingHeaderId;
let activeTimestampWithRepeaterHeaderId;
let repeatingHeaderWithDayRepeaterId;
let repeatingHeaderWithHourRepeaterId;
let state;
const testOrgFile = readFixture('various_todos');
const path = 'testfile';
Expand All @@ -841,6 +845,14 @@ describe('org reducer', () => {
.get(3)
.get('id');
repeatingHeaderId = state.org.present.getIn(['files', path, 'headers']).get(4).get('id');
repeatingHeaderWithDayRepeaterId = state.org.present
.getIn(['files', path, 'headers'])
.get(5)
.get('id');
repeatingHeaderWithHourRepeaterId = state.org.present
.getIn(['files', path, 'headers'])
.get(6)
.get('id');
});

function check_todo_keyword_kept(oldHeaders, newHeaders, headerId) {
Expand Down Expand Up @@ -986,6 +998,45 @@ describe('org reducer', () => {
).toMatch(/<2020-11-16 Mon \+1d>/);
});

it('should not update the timestamp for a repeating task with +1d repeater', () => {
const oldHeaders = state.org.present.getIn(['files', path, 'headers']);
const { startHour, startMinute } = headerWithId(oldHeaders, repeatingHeaderWithDayRepeaterId)
.getIn(['planningItems', 0, 'timestamp'])
.toJS();

const newHeaders = reducer(
state.org.present,
types.advanceTodoState(repeatingHeaderWithDayRepeaterId)
).getIn(['files', path, 'headers']);
const newTimestamp = headerWithId(newHeaders, repeatingHeaderWithDayRepeaterId)
.getIn(['planningItems', 0, 'timestamp'])
.toJS();
expect(newTimestamp.startHour).toEqual(startHour);
expect(newTimestamp.startMinute).toEqual(startMinute);
});

it('should update the timestamp for a repeating task with +1h repeater', () => {
const oldHeaders = state.org.present.getIn(['files', path, 'headers']);
const { startHour, startMinute } = headerWithId(oldHeaders, repeatingHeaderWithHourRepeaterId)
.getIn(['planningItems', 0, 'timestamp'])
.toJS();

const newHeaders = reducer(
state.org.present,
types.advanceTodoState(repeatingHeaderWithHourRepeaterId)
).getIn(['files', path, 'headers']);
const newTimestamp = headerWithId(newHeaders, repeatingHeaderWithHourRepeaterId)
.getIn(['planningItems', 0, 'timestamp'])
.toJS();
let now = new Date();
if (now.getHours() != startHour) {
expect(newTimestamp.startHour).not.toEqual(startHour);
}
if (now.getMinutes() != startMinute) {
expect(newTimestamp.startMinute).not.toEqual(startMinute);
}
});

it('should just dirty when applied to no header', () => {
check_just_dirtying(state.org.present, types.advanceTodoState(undefined));
});
Expand Down
11 changes: 10 additions & 1 deletion test_helpers/fixtures/various_todos.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
* This is not a todo
* TODO Task with active timestamp and repeater <2020-11-15 Sun +1d>
* TODO Repeating task
SCHEDULED: <2019-11-27 Wed +1d>
SCHEDULED: <2019-11-28 Thu +1d>
* TODO Repeating task with +1d repeater
SCHEDULED: <2021-05-17 Mon 08:00 .+1d>

When repeaterUnit is not "h", hour and minutes are never touched.
* TODO Repeating task with +1h repeater
SCHEDULED: <2021-05-17 Mon 08:00 .+1h>

When repeaterUnit is "h", hour and minutes are set to
n hour(s) from now.

0 comments on commit 94ef624

Please sign in to comment.