Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add tests for repeating task with +1d and +1h repeaters #750

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/reducers/org.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('org reducer', () => {
state.org.present = state.org.present
.setIn(['files', path], parseOrg(contents))
.set('path', path);

return state;
}

Expand Down Expand Up @@ -822,6 +823,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 +844,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 @@ -906,6 +917,10 @@ describe('org reducer', () => {
const oldHeaders = state.org.present.getIn(['files', path, 'headers']);
const newHeaders = reducer(
state.org.present,
// XXX: Why did this even work? `advanceTodoState` should have
// a second argument `logIntoDrawer` that should need to be
// set to `true` here. However, even setting it to `true` now
// does not help.
types.advanceTodoState(repeatingHeaderId)
).getIn(['files', path, 'headers']);
check_todo_keyword_kept(oldHeaders, newHeaders, repeatingHeaderId);
Expand Down Expand Up @@ -986,6 +1001,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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why the expectation fails is this line. Adding another headline to various_todos.org after the * TODO Repeating task leads to the log drawer not to be build.

Unfortunately, the reason is unclear to me.

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.