Skip to content

Commit

Permalink
update the test files to remove unnecessary and repeated code
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdking committed Jul 13, 2017
1 parent 244ee49 commit f31a56f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 191 deletions.
2 changes: 0 additions & 2 deletions logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ var todoFunctions = {
var repeatedTodo = false;
todos.forEach(function(todo) {
if (newTodo.description === todo.description){
// console.log('new: ', newTodo.description);
// console.log('old: ', todo.description);
repeatedTodo = true;
}
})
Expand Down
226 changes: 37 additions & 189 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,52 @@
var test = require('tape');
var logic = require('./logic');

test('Example test', function(t) {
t.pass();
t.end();
});

// tests for generateId //


// up to here //
var todos = [{
id: 0,
description: 'smash avocados',
done: false
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var todosCopy = [{
id: 0,
description: 'smash avocados',
done: false
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var newTodo = {description: "Help I can't code"}

// tests for addTodo function //
test('no newTodo input returns unchanged todos object', function(t) {
var todos = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var todosCopy = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
test('addTodo takes an array of all todos and the description of the new todo, and it returns a new array with a new todo attached with an original id', function(t) {
var actual = logic.todoFunctions.addTodo(todos)
var expected = todos
t.equal(actual, expected);
t.deepEqual(actual, todosCopy);
t.deepEqual(actual, todosCopy, 'if no new todo should return unchanged todos');
t.end();
})

test('check todos has added newtodo',function(t){
var newTodo = {
id: 2,
description:'wash dishes',
done: true
}
var todos = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var actual = logic.todoFunctions.addTodo(todos,newTodo);
var expected = todos.concat(newTodo);
t.deepEqual(actual, expected);
t.deepEqual(actual, expected, 'should add newtodo to array of todos');
t.end();
})

test('check newTodo has a new id', function(t) {
var todos = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var newTodo = {description: "Help I can't code"}
var actual = logic.todoFunctions.addTodo(todos, newTodo)
var expected = [{
id: 0,
description: 'smash avocados',
done: true
done: false
},
{
id: 1,
Expand All @@ -95,139 +59,57 @@ test('check newTodo has a new id', function(t) {
done: false
}
]
t.deepEqual(actual, expected);
t.deepEqual(actual, expected, 'new todo should have a unique id');
t.end();
})

test('empty string as newtodo description returns unchanged todos object', function(t) {
var todos = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var newTodo = {description: ''};
var actual = logic.todoFunctions.addTodo(todos, newTodo)
var expected = todos
t.deepEqual(actual,expected);
t.deepEqual(actual, expected, 'if new todo is an empty string should return unchanged todos');
t.end();
})

test('if newtodo matches old todos return unchanged todos' , function(t){
var todos = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var newTodo = {description: 'smash avocados'}
var actual = logic.todoFunctions.addTodo(todos, newTodo)
var expected = todos
t.deepEqual(actual, expected);
t.deepEqual(actual, expected, 'if duplicating old todo should return unchanged todos');
t.end();
})

// up to here //

// tests for deleteTodo function //
test("if no idToDelete input return same todos", function(t) {
var todos = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var actual = logic.todoFunctions.deleteTodo(todos);
var expected = todos;
t.deepEqual(actual, expected);
t.deepEqual(actual, expected, 'if no input id should return unchanged todos');
t.end();
})

test("new todos array deleted object with idToDelete", function(t) {
var todos = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var todosCopy = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var idToDelete = 1;
var actual = logic.todoFunctions.deleteTodo(todos, idToDelete);
var expected = [{
id: 0,
description: 'smash avocados',
done: true
done: false
}];
t.deepEqual(actual, expected);
t.deepEqual(todos, todosCopy)
t.deepEqual(actual, expected, 'should return todos minus the object with id to delete');
t.deepEqual(todos, todosCopy, 'checck not mutating original todos input')
t.end();
})

test('if idToDelete doesnt exist return unchanged todos', function(t){
var todos = [{
id: 0,
description: 'smash avocados',
done: true
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var idToDelete = 2
var actual = logic.todoFunctions.deleteTodo(todos, idToDelete);
var expected = todos
t.deepEqual(actual, expected);
t.deepEqual(actual, expected, 'if idtodelete does not exist return unchanged todos');
t.end();
})


// up to here

// tests for markTodo function //
test("change done to true", function(t) {
var todos = [{
id: 0,
description: 'smash avocados',
done: false
},
{
id: 1,
description: 'make coffee',
done: false
}
];
var actual = logic.todoFunctions.markTodo(todos, 0);
var expected = [{
id: 0,
Expand All @@ -240,7 +122,7 @@ test("change done to true", function(t) {
done: false
}
];
t.deepEqual(actual, expected);
t.deepEqual(actual, expected, 'change done to true on todo with id to mark');
t.end();
})

Expand Down Expand Up @@ -268,40 +150,6 @@ test('change from done to undone', function(t) {
}
];
var actual = logic.todoFunctions.markTodo(todos, 0);
t.deepEqual(actual, expected);
t.deepEqual(actual, expected, 'change done to false on todo with id to mark');
t.end();
})

// up to here //

// tests for sort function //
// test('sort todos by id', function(t){
// var todos = [{
// id: 1,
// description: 'smash avocados',
// done: true
// },
// {
// id: 0,
// description: 'make coffee',
// done: false
// }
// ];
// var actual = logic.todoFunctions.sortTodos(todos, sortFunction);
// var expected = [{
// id: 0,
// description: 'smash avocados',
// done: true
// },
// {
// id: 1,
// description: 'make coffee',
// done: false
// }
// ];
// t.deepEqual(actual, expected);
// t.end();
// })
//

// up to here //

0 comments on commit f31a56f

Please sign in to comment.