Add false return when repeats are empty (#8777)

* Add false return when repeats are empty

* Added front end check for repeats on monthly-daysOfWeek

* Fixed tests with static date
This commit is contained in:
Keith Holliday
2017-06-14 12:27:50 -06:00
committed by Sabe Jones
parent c084f8a2b9
commit f7ce269f3c
4 changed files with 43 additions and 5 deletions

View File

@@ -713,8 +713,9 @@ describe('shouldDo', () => {
it('leaves daily inactive if not day of the month', () => { it('leaves daily inactive if not day of the month', () => {
dailyTask.everyX = 1; dailyTask.everyX = 1;
dailyTask.frequency = 'monthly'; dailyTask.frequency = 'monthly';
dailyTask.daysOfMonth = [15]; let today = moment();
let tomorrow = moment().add(1, 'day').toDate();// @TODO: make sure this is not the 15 dailyTask.daysOfMonth = [today.date()];
let tomorrow = today.add(1, 'day').toDate();
expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false); expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false);
}); });
@@ -732,8 +733,9 @@ describe('shouldDo', () => {
it('leaves daily inactive if not on date of the x month', () => { it('leaves daily inactive if not on date of the x month', () => {
dailyTask.everyX = 2; dailyTask.everyX = 2;
dailyTask.frequency = 'monthly'; dailyTask.frequency = 'monthly';
dailyTask.daysOfMonth = [15]; let today = moment();
let tomorrow = moment().add(2, 'months').add(1, 'day').toDate(); dailyTask.daysOfMonth = [today.date()];
let tomorrow = today.add(2, 'months').add(1, 'day').toDate();
expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false); expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false);
}); });
@@ -911,6 +913,28 @@ describe('shouldDo', () => {
expect(shouldDo(day, dailyTask, options)).to.equal(false); expect(shouldDo(day, dailyTask, options)).to.equal(false);
}); });
it('returns false when next due is requested and no repeats are available', () => {
dailyTask.repeat = {
su: false,
s: false,
f: false,
th: false,
w: false,
t: false,
m: false,
};
let today = moment('2017-05-27T17:34:40.000Z');
let week = today.monthWeek();
dailyTask.startDate = today.toDate();
dailyTask.weeksOfMonth = [week];
dailyTask.everyX = 1;
dailyTask.frequency = 'monthly';
day = moment('2017-02-23');
options.nextDue = true;
expect(shouldDo(day, dailyTask, options)).to.equal(false);
});
it('activates Daily if correct week of the month on the day of the start date', () => { it('activates Daily if correct week of the month on the day of the start date', () => {
dailyTask.repeat = { dailyTask.repeat = {
su: false, su: false,

View File

@@ -38,6 +38,18 @@ angular.module('habitrpg')
} }
function saveTask (task, stayOpen, isSaveAndClose) { function saveTask (task, stayOpen, isSaveAndClose) {
// Ensure user has a repeat day selected for monthly day of the week
var taskIsDayOfTheWeekMonthly = task._edit.frequency === 'monthly' && task._edit.repeatsOn == 'dayOfWeek';
var repeats = _.values(task._edit.repeat);
var repeatHasTrueDay = _.find(repeats, function (item) {
return item === true;
});
if (taskIsDayOfTheWeekMonthly && !repeatHasTrueDay) {
alert(env.t('repeatDayError'));
return;
}
if (task._edit) { if (task._edit) {
angular.copy(task._edit, task); angular.copy(task._edit, task);
} }

View File

@@ -169,5 +169,6 @@
"yearlyRepeatHelpContent": "This task will be due every X years", "yearlyRepeatHelpContent": "This task will be due every X years",
"resets": "Resets", "resets": "Resets",
"summaryStart": "Repeats <%= frequency %> every <%= everyX %> <%= frequencyPlural %> ", "summaryStart": "Repeats <%= frequency %> every <%= everyX %> <%= frequencyPlural %> ",
"nextDue": "Next Due Dates" "nextDue": "Next Due Dates",
"repeatDayError": "Please ensure that you have at least one day of the week selected."
} }

View File

@@ -164,6 +164,7 @@ export function shouldDo (day, dailyTask, options = {}) {
let matchEveryX = differenceInMonths % dailyTask.everyX === 0; let matchEveryX = differenceInMonths % dailyTask.everyX === 0;
if (dailyTask.weeksOfMonth && dailyTask.weeksOfMonth.length > 0) { if (dailyTask.weeksOfMonth && dailyTask.weeksOfMonth.length > 0) {
if (daysOfTheWeek.length === 0) return false;
schedule = schedule.every(daysOfTheWeek).daysOfWeek() schedule = schedule.every(daysOfTheWeek).daysOfWeek()
.every(dailyTask.weeksOfMonth).weeksOfMonthByDay(); .every(dailyTask.weeksOfMonth).weeksOfMonthByDay();