Implements repeat every X days since last completion (Fixes #6941) (#8962)

* Implemented repeat after completion

* Added tests for repeat after completion in shouldDo.test.js

* Remove lastTicked

* Undoes removal of website/client/README.md
This commit is contained in:
Asif Mallik
2017-11-08 00:56:46 +06:00
committed by Sabe Jones
parent 19500600bc
commit 9d69d4b863
6 changed files with 96 additions and 4 deletions

View File

@@ -278,6 +278,68 @@ describe('shouldDo', () => {
});
});
context('When repeat after completion is on', () => {
beforeEach(() => {
dailyTask.repeatAfterCompletion = true;
dailyTask.everyX = 5;
day = moment('2017-05-01').toDate();
dailyTask.startDate = day;
});
context('last completed is set', () => {
beforeEach(() => {
day = moment('2017-05-03').toDate();
dailyTask.lastCompleted = day;
});
it('should compute daily nextDue values', () => {
options.timezoneOffset = 0;
options.nextDue = true;
nextDue = shouldDo(day, dailyTask, options);
expect(nextDue.length).to.eql(6);
expect(moment(nextDue[0]).toDate()).to.eql(moment.utc('2017-05-08').toDate());
expect(moment(nextDue[1]).toDate()).to.eql(moment.utc('2017-05-09').toDate());
expect(moment(nextDue[2]).toDate()).to.eql(moment.utc('2017-05-10').toDate());
expect(moment(nextDue[3]).toDate()).to.eql(moment.utc('2017-05-11').toDate());
expect(moment(nextDue[4]).toDate()).to.eql(moment.utc('2017-05-12').toDate());
expect(moment(nextDue[5]).toDate()).to.eql(moment.utc('2017-05-13').toDate());
});
it('returns false before X Days passes after completion', () => {
day = moment('2017-05-05').toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(false);
});
it('returns true after X Days passes after completion', () => {
day = moment('2017-05-10').toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(true);
});
});
context('last completed is not set', () => {
it('should compute daily nextDue values', () => {
options.timezoneOffset = 0;
options.nextDue = true;
nextDue = shouldDo(day, dailyTask, options);
expect(nextDue.length).to.eql(6);
expect(moment(nextDue[0]).toDate()).to.eql(moment.utc('2017-05-02').toDate());
expect(moment(nextDue[1]).toDate()).to.eql(moment.utc('2017-05-03').toDate());
expect(moment(nextDue[2]).toDate()).to.eql(moment.utc('2017-05-04').toDate());
expect(moment(nextDue[3]).toDate()).to.eql(moment.utc('2017-05-05').toDate());
expect(moment(nextDue[4]).toDate()).to.eql(moment.utc('2017-05-06').toDate());
expect(moment(nextDue[5]).toDate()).to.eql(moment.utc('2017-05-07').toDate());
});
it('returns true after start date', () => {
day = moment('2017-05-04').toDate();
expect(shouldDo(day, dailyTask, options)).to.equal(true);
});
});
});
context('If number of X days is zero', () => {
beforeEach(() => {
dailyTask.everyX = 0;