Refactor clone challenges PR

This commit is contained in:
Blade Barringer
2015-06-19 20:49:24 -05:00
parent deff0d4da2
commit 86f18e9a5a
5 changed files with 455 additions and 120 deletions

View File

@@ -22,7 +22,7 @@ describe('Tasks Service', function() {
var task;
beforeEach(function(){
task = { id: 'task-id' }; // @TODO: replace with task factory
task = newTask();
});
it('toggles the _editing property', function() {
@@ -66,4 +66,216 @@ describe('Tasks Service', function() {
expect(rootScope.charts[task.id]).to.eql(false);
});
});
describe('cloneTask', function() {
context('generic tasks', function() {
it('clones the data from a task', function() {
var task = newTask();
var clonedTask = tasks.cloneTask(task);
expect(clonedTask.text).to.eql(task.text);
expect(clonedTask.notes).to.eql(task.notes);
expect(clonedTask.tags.includedTag).to.eql(task.tags.includedTag);
expect(clonedTask.tags.notIncludedTag).to.eql(task.tags.notIncludedTag);
expect(clonedTask.priority).to.eql(task.priority);
expect(clonedTask.attribute).to.eql(task.attribute);
});
it('does not clone original task\'s id or _id', function() {
var task = newTask();
var clonedTask = tasks.cloneTask(task);
expect(clonedTask.id).to.exist;
expect(clonedTask.id).to.not.eql(task.id);
expect(clonedTask._id).to.exist;
expect(clonedTask._id).to.not.eql(task._id);
});
it('does not clone original task\'s dateCreated attribute', function() {
var task = newTask({
dateCreated: new Date(2014, 5, 1, 1, 1, 1, 1),
});
var clonedTask = tasks.cloneTask(task);
expect(clonedTask.dateCreated).to.exist;
expect(clonedTask.dateCreated).to.not.eql(task.dateCreated);
});
it('does not clone original task\'s value', function() {
var task = newTask({
value: 130
});
var clonedTask = tasks.cloneTask(task);
expect(clonedTask.value).to.exist;
expect(clonedTask.value).to.not.eql(task.value);
});
});
context('Habits', function() {
it('clones a habit', function() {
var habit = newHabit({
up: true,
down: false
});
var clonedHabit = tasks.cloneTask(habit);
expect(clonedHabit.type).to.eql('habit');
expect(clonedHabit.up).to.eql(habit.up);
expect(clonedHabit.down).to.eql(habit.down);
});
});
context('Dailys', function() {
it('clones a daily', function() {
var daily = newDaily({
frequency: 'daily',
everyX: 3,
startDate: new Date(2014, 5, 1, 1, 1, 1, 1),
});
var clonedDaily = tasks.cloneTask(daily);
expect(clonedDaily.type).to.eql('daily');
expect(clonedDaily.frequency).to.eql(daily.frequency);
expect(clonedDaily.everyX).to.eql(daily.everyX);
expect(clonedDaily.startDate).to.eql(daily.startDate);
});
it('does not clone streak', function() {
var daily = newDaily({
streak: 11
});
var clonedDaily = tasks.cloneTask(daily);
expect(clonedDaily.streak).to.eql(0);
});
});
context('Todos', function() {
it('clones a todo', function() {
var todo = newTodo();
var clonedTodo = tasks.cloneTask(todo);
expect(clonedTodo.type).to.eql('todo');
});
it('does not clone due date', function() {
var todo = newTodo({
date: '2015-06-20'
});
var clonedTodo = tasks.cloneTask(todo);
expect(clonedTodo.date).to.not.exist;
});
it('does not clone date completed', function() {
var todo = newTodo({
dateCompleted: new Date()
});
var clonedTodo = tasks.cloneTask(todo);
expect(clonedTodo.dateCompleted).to.not.exist;
});
});
context('Rewards', function() {
it('clones a reward', function() {
var reward = newReward();
var clonedReward = tasks.cloneTask(reward);
expect(clonedReward.type).to.eql('reward');
});
it('does clone a reward\'s value', function() {
var reward = newReward({
value: 20
});
var clonedReward = tasks.cloneTask(reward);
expect(clonedReward.value).to.eql(reward.value);
});
});
context('complete', function() {
it('does not clone completed status', function() {
var todo = newTodo({
completed: true
});
var clonedTodo = tasks.cloneTask(todo);
expect(clonedTodo.completed).to.eql(false);
});
});
context('history', function() {
it('does not clone history', function() {
var habit = newHabit({
history: [
{ date: Date.now, value: 3.1 },
{ date: Date.now, value: 2.7 }
]
});
var clonedHabit = tasks.cloneTask(habit);
expect(clonedHabit.history).to.be.an.array;
expect(clonedHabit.history).to.be.empty;
});
});
context('checklists', function() {
it('clones checklist text', function() {
var todo = newTodo({
checklist: [{
completed: true,
text: 'checklist 1',
id: 'cl-1'
}, {
completed: false,
text: 'checklist 2',
id: 'cl-2'
}]
});
var clonedTodo = tasks.cloneTask(todo);
expect(clonedTodo.checklist[0].text).to.eql(todo.checklist[0].text);
expect(clonedTodo.checklist[1].text).to.eql(todo.checklist[1].text);
});
it('does not clone complete or id attribute of checklist', function() {
var todo = newTodo({
checklist: [{
completed: true,
text: 'checklist 1',
id: 'cl-1'
}, {
completed: false,
text: 'checklist 2',
id: 'cl-2'
}]
});
var clonedTodo = tasks.cloneTask(todo);
expect(clonedTodo.checklist[0].completed).to.eql(false);
expect(clonedTodo.checklist[0].id).to.not.eql(todo.checklist[0].id);
expect(clonedTodo.checklist[0].id).to.exist;
expect(clonedTodo.checklist[1].completed).to.eql(false);
expect(clonedTodo.checklist[1].id).to.not.eql(todo.checklist[1].id);
expect(clonedTodo.checklist[1].id).to.exist;
});
});
});
});