diff --git a/package.json b/package.json index a87fa31..b9383bc 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "main": "src/server.js", "scripts": { + "start:fe:dev": "webpack-dev-server --hot --inline --content-base static", "test": "tape -r babel-register 'src/**/*spec.js'" }, "babel": { @@ -19,7 +20,10 @@ "babel-preset-stage-0": "^6.5.0" }, "devDependencies": { + "babel-loader": "^6.2.10", "babel-register": "^6.14.0", - "tape": "^4.6.0" + "tape": "^4.6.0", + "webpack": "^1.14.0", + "webpack-dev-server": "^1.16.2" } } diff --git a/src/Todo.js b/src/Todo.js new file mode 100644 index 0000000..e69de29 diff --git a/src/Todo.spec.js b/src/Todo.spec.js new file mode 100644 index 0000000..379735a --- /dev/null +++ b/src/Todo.spec.js @@ -0,0 +1,59 @@ +import test from 'tape'; +import Todo from './Todo'; + +test( 'Todo', t => { + let actual, expected, todo; + let testTodo = { + id: 'test', + title: 'Test', + complete: true, + }; + + todo = Todo( testTodo ); // use new if using a constructor + + actual = todo.getId(); + expected = testTodo.id; + t.equal( actual, expected, 'with object, should store the id' ); + + actual = todo.getTitle(); + expected = testTodo.title; + t.equal( actual, expected, 'with object, should store the title' ); + + actual = todo.isComplete(); + expected = testTodo.complete; + t.equal( actual, expected, 'with object, should store the completion' ); + + todo = Todo( 'Test' ); // use new if using a constructor + + actual = typeof todo.getId(); + expected = 'string'; + t.equal( actual, expected, 'with title, should generate an id' ); + + actual = todo.getTitle(); + expected = 'Test'; + t.equal( actual, expected, 'with title, should store the title' ); + + actual = todo.isComplete(); + expected = false; + t.equal( actual, expected, 'with title, should default to not complete' ); + + todo = Todo( 'Test' ); // use new if using a constructor + todo.toggleComplete(); + actual = todo.isComplete(); + expected = true; + t.equal( actual, expected, 'toggleComplete should complete uncompleted todos' ); + + todo.toggleComplete(); + actual = todo.isComplete(); + expected = false; + t.equal( actual, expected, 'toggleComplete should uncomplete completed todos' ); + + todo = Todo( 'Test' ); // use new if using a constructor + todo.setTitle( 'New' ); + actual = todo.getTitle(); + expected = 'New'; + t.equal( actual, expected, 'setTitle should change the title' ); + + t.end(); +}); + diff --git a/src/TodoApp.js b/src/TodoApp.js new file mode 100644 index 0000000..e69de29 diff --git a/src/TodoApp.spec.js b/src/TodoApp.spec.js new file mode 100644 index 0000000..67a0c8c --- /dev/null +++ b/src/TodoApp.spec.js @@ -0,0 +1,70 @@ +import test from 'tape'; +import TodoApp from './TodoApp'; +import Todo from './Todo'; + +test( 'TodoApp', t => { + let actual, expected, app; + + // app = TodoApp(); // use new if using a constructor + + actual = app.isFiltered(); + expected = false; + t.deepEqual( actual, expected, 'should begin without a filter' ); + + actual = app.getTodos(); + expected = []; + t.deepEqual( actual, expected, 'should begin an empty set of todos' ); + + app.addTodo( 'Test' ); + + actual = app.getTodos().length; + expected = 1; + t.equal( actual, expected, 'addTodo should add a todo' ); + + let [ todo ] = app.getTodos(); + actual = typeof todo.getTitle; + actual = 'function'; + t.ok( actual, 'addTodo should add todos as Todo instances' ); + + actual = todo.getTitle(); + expected = 'Test'; + t.equal( actual, expected, 'addTodo should set the title of the todo to that passed' ); + + app.toggleFilter(); + todo.toggleComplete(); + actual = app.getTodos().length; + expected = 0; + t.equal( actual, expected, 'should use filter to hide todos' ); + + app.toggleFilter(); + actual = app.getTodos().length; + expected = 1; + t.equal( actual, expected, 'should show all todos when filter removed' ); + + app.rmTodo( todo.getId() ); + actual = app.getTodos().length; + expected = 0; + t.equal( actual, expected, 'rmTodo should remove a todo by its id' ); + + app.setTodos([ Todo( '1' ), Todo( '2' ) ]); // use new if using a constructor + actual = app.getTodos().length; + expected = 2; + t.equal( actual, expected, 'setTodos should replace all todos witht those provided' ); + + app = TodoApp(); // use new if using a constructor + app.addTodo({ id: '1', complete: false, title: 'One' }); + app.addTodo({ id: '2', complete: false, title: 'Two' }); + + app.toggleComplete( '1' ); + let [ todo1, todo2 ] = app.getTodos(); + t.equal( todo1.isComplete(), true, 'toggleComplete should toggle the status of the todo' ); + t.equal( todo2.isComplete(), false, 'toggleComplete should not toggle other todos' ); + + app.setTitle( '2', 'New' ); + [ todo1, todo2 ] = app.getTodos(); + t.equal( todo1.getTitle(), 'One', 'setTitle should not change other todos' ); + t.equal( todo2.getTitle(), 'New', 'setTitle should change the title of the todo' ); + + t.end(); +}); + diff --git a/src/index.js b/src/index.js index c1b4585..30e1a0f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,41 +1,35 @@ -export function double ( x ) { - return x * 2; -} - -export function doubleXTimes ( x, num ) { - let result = x; - - // i++ === i = i + 1 - // what is the difference between using let and var? - for ( let i = 0; i < num; i++ ) { - // result = result * 2; - result = double( result ); // internal implementation detail - } +function onReady () { + const addTodoForm = document.getElementById( 'addTodoForm' ); + const todoList = document.getElementById( 'todoList' ); + const newTodoText = document.getElementById( 'newTodoText' ); - return result; -} + //