From f31a56ffa3dba583e0d1e66e216a58a51cdf915a Mon Sep 17 00:00:00 2001 From: matthewdking Date: Thu, 13 Jul 2017 11:50:38 +0300 Subject: [PATCH] update the test files to remove unnecessary and repeated code #48 #29 #26 #30 --- logic.js | 2 - test.js | 226 +++++++++---------------------------------------------- 2 files changed, 37 insertions(+), 191 deletions(-) diff --git a/logic.js b/logic.js index e98a874..11dbc9c 100644 --- a/logic.js +++ b/logic.js @@ -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; } }) diff --git a/test.js b/test.js index 031a6f2..8329c09 100644 --- a/test.js +++ b/test.js @@ -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, @@ -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, @@ -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(); }) @@ -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 //