From 94ef624dce40c5341d2498a4e59bac5399e43ad7 Mon Sep 17 00:00:00 2001 From: "Alain M. Lafon" Date: Tue, 9 Nov 2021 10:54:06 +0100 Subject: [PATCH] test: Add tests for repeating task with +1d and +1h repeaters --- src/reducers/org.unit.test.js | 51 +++++++++++++++++++++++++ test_helpers/fixtures/various_todos.org | 11 +++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/reducers/org.unit.test.js b/src/reducers/org.unit.test.js index 9e41d7a69..4f368647d 100644 --- a/src/reducers/org.unit.test.js +++ b/src/reducers/org.unit.test.js @@ -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; } @@ -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'; @@ -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) { @@ -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)); }); diff --git a/test_helpers/fixtures/various_todos.org b/test_helpers/fixtures/various_todos.org index c12c37a9c..869572b0f 100644 --- a/test_helpers/fixtures/various_todos.org +++ b/test_helpers/fixtures/various_todos.org @@ -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.