Files
habitica/test/common/libs/taskDefaults.test.js
astolat 6d0df78441 Habits v2: adding counter to habits (cleaned up branch) - fixes #8113 (#8198)
* Clean version of PR 8175

The original PR for this was here:
https://github.com/HabitRPG/habitica/pull/8175

Unfortunately while fixing a conflict in tasks.json, I messed up the rebase and wound up pulling in too many commits and making a giant mess. Sorry. :P

* Fixing test failure

This test seems to occasionally start failing (another coder reported the same thing happening to them in the blacksmiths’ guild) because the order in which the tasks are created can sometimes not match the order in the array. So I have sorted the tasks array after creation by the task name to ensure a consistent ordering, and slightly reordered the expect statements to match.
2017-02-27 11:15:45 -07:00

65 lines
1.9 KiB
JavaScript

import taskDefaults from '../../../website/common/script/libs/taskDefaults';
describe('taskDefaults', () => {
it('applies defaults to undefined type or habit', () => {
let task = taskDefaults();
expect(task.type).to.eql('habit');
expect(task._id).to.exist;
expect(task.text).to.eql(task._id);
expect(task.tags).to.eql([]);
expect(task.value).to.eql(0);
expect(task.priority).to.eql(1);
expect(task.up).to.eql(true);
expect(task.down).to.eql(true);
expect(task.history).to.eql([]);
expect(task.frequency).to.equal('daily');
expect(task.counterUp).to.equal(0);
expect(task.counterDown).to.equal(0);
});
it('applies defaults to a daily', () => {
let task = taskDefaults({ type: 'daily' });
expect(task.type).to.eql('daily');
expect(task._id).to.exist;
expect(task.text).to.eql(task._id);
expect(task.tags).to.eql([]);
expect(task.value).to.eql(0);
expect(task.priority).to.eql(1);
expect(task.history).to.eql([]);
expect(task.completed).to.eql(false);
expect(task.streak).to.eql(0);
expect(task.repeat).to.eql({
m: true,
t: true,
w: true,
th: true,
f: true,
s: true,
su: true,
});
expect(task.frequency).to.eql('weekly');
expect(task.startDate).to.exist;
});
it('applies defaults a reward', () => {
let task = taskDefaults({ type: 'reward' });
expect(task.type).to.eql('reward');
expect(task._id).to.exist;
expect(task.text).to.eql(task._id);
expect(task.tags).to.eql([]);
expect(task.value).to.eql(10);
expect(task.priority).to.eql(1);
});
it('applies defaults a todo', () => {
let task = taskDefaults({ type: 'todo' });
expect(task.type).to.eql('todo');
expect(task._id).to.exist;
expect(task.text).to.eql(task._id);
expect(task.tags).to.eql([]);
expect(task.value).to.eql(0);
expect(task.priority).to.eql(1);
expect(task.completed).to.eql(false);
});
});