mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
add handling and tests for new timetravelers schedule
This commit is contained in:
@@ -10,7 +10,7 @@ function validateMatcher (matcher, checkedDate) {
|
|||||||
expect(matcher.end).to.be.greaterThan(checkedDate);
|
expect(matcher.end).to.be.greaterThan(checkedDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Content Schedule', () => {
|
describe.only('Content Schedule', () => {
|
||||||
it('assembles scheduled items on january 15th', () => {
|
it('assembles scheduled items on january 15th', () => {
|
||||||
const date = new Date('2024-01-15');
|
const date = new Date('2024-01-15');
|
||||||
const matchers = getAllScheduleMatchingGroups(date);
|
const matchers = getAllScheduleMatchingGroups(date);
|
||||||
@@ -120,4 +120,32 @@ describe('Content Schedule', () => {
|
|||||||
expect(matcher.match('backgroundkey082021')).to.be.true;
|
expect(matcher.match('backgroundkey082021')).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('timeTravelers matcher', () => {
|
||||||
|
it('allows sets matching the month', () => {
|
||||||
|
const date = new Date('2024-07-08');
|
||||||
|
const matcher = getAllScheduleMatchingGroups(date).timeTravelers;
|
||||||
|
expect(matcher.match('202307')).to.be.true;
|
||||||
|
expect(matcher.match('202207')).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('disallows sets not matching the month', () => {
|
||||||
|
const date = new Date('2024-07-08');
|
||||||
|
const matcher = getAllScheduleMatchingGroups(date).timeTravelers;
|
||||||
|
expect(matcher.match('202306')).to.be.false;
|
||||||
|
expect(matcher.match('202402')).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('disallows sets from current month', () => {
|
||||||
|
const date = new Date('2024-07-08');
|
||||||
|
const matcher = getAllScheduleMatchingGroups(date).timeTravelers;
|
||||||
|
expect(matcher.match('202407')).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('disallows sets from the future', () => {
|
||||||
|
const date = new Date('2024-07-08');
|
||||||
|
const matcher = getAllScheduleMatchingGroups(date).backgrounds;
|
||||||
|
expect(matcher.match('202507')).to.be.false;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,9 +24,13 @@ function backgroundMatcher (month1, month2, oddYear) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function timeTravelersMatcher (month1, month2) {
|
function timeTravelersMatcher (month1, month2) {
|
||||||
return function call (item) {
|
return function call (item, date) {
|
||||||
const itemMonth = parseInt(item.substring(4, 6), 10);
|
const month = parseInt(item.substring(4, 6), 10);
|
||||||
return itemMonth === month1 || itemMonth === month2;
|
const year = parseInt(item.substring(0, 4), 10);
|
||||||
|
if (date.getFullYear() === year && (date.getMonth() + 1) >= month) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return month === month1 || month === month2;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user