Goal: Create a working, single page app.
Create a github project named Shopping-List
This project has 3 parts.
- The Shopping List BDD tests
- Building the Shopping List classes to make tests pass
- Rendering a shopping list to the browser
use http-server to test and run your app
Setup Mocha and Chai to run tests on your application in the browser.
Shopping-List/
node_modules/
mocha/
chai/
js/
shopping_list_test.js
tests.html
Write tests for the shopping list application.
The tests should describe the following shopping list functionality:
- ShoppingListItem is a class
- ShoppingListItem has a property named
name
- ShoppingListItem has a property named
description
- ShoppingListItem has a property named
is_done
- ShoppingListItem has a constructor method that accepts 2 arguments,
name
anddescription
- the constructor method sets the new instances
name
anddescription
properties using the arguments passed in
- the constructor method sets the new instances
- ShoppingListItem has a method named
check
- calling the instance's
check
method will set it'sis_done
property to true
- calling the instance's
- ShoppingListItem has a method named
uncheck
- calling the instance's
uncheck
method will set it'sis_done
property to false
- calling the instance's
- ShoppingListItem has a method named
render
- calling the instance's
render
method will construct and return an html formatted string. the string content will be wrapped in " - " tags.
<li class="completed_[is_done]"><span>[name]</span> <span>[description]</span></li>
. example:<li class="completed_false"><span>Avocado</span> <span>Must be eaten immediately.</span></li>
- calling the instance's
hint: multiline strings in javascript need to be "escaped"
example:
var some_html_output = '<ul> \
<li class="completed_false"> \
<span>Avocado</span> \
<span>Must be eaten immediately.</span> \
</li> \
<ul>';
- ShoppingList is a class
- ShoppingList has a property named
items
- ShoppingList has a constructor method that initializes
items
as an empty Array - ShoppingList has a method named
addItem
that accepts a single ShoppingListItem argument- invoking the
addItem
method by passing in a ShoppingListItem object should add that object to theitems
array - invoking the
addItem
method by passing in anything else that is not a ShoppingListItem object should immediately throw an error
- invoking the
- ShoppingList has a method named
removeItem
that accepts a single ShoppingListItem argument- invoking the
removeItem
method by passing in a ShoppingListItem object (that exists in theitems
array) should remove that object from theitems
array - invoking the
removeItem
method with no parameters should remove the last item in theitems
list, if there are any items, else it does nothing - invoking the
removeItem
method by passing in anything else that is not a ShoppingListItem object (that exists in theitems
array) should immediately throw an error
- invoking the
- ShoppingList has a method named
render
- calling the instance's
render
method will concatenate the result of callingrender()
on each item in this object'sitems
array, wrapping it in a "- " tags, and returning an html formatted string. ex:
<ul>...[all the li elements from ShoppingListItem.render()]...</ul>
standard html5 document before the end of this body tag, include your test library dependencies and your test file.
you should be able to run your tests with all tests failing, commit and push your work.
Create implementation files.
shopping_list_item.js
shopping_list.js
Shopping-List/ node_modules/ mocha/ chai/ js/ shopping_list_item.js shopping_list.js shopping_list_test.js tests.html
standard html5 document before the end of this body tag, include your 2 shopping list scripts.
Create a class that defines
ShoppingListItem
.
ShoppingListItem
will have all the properties and methods defined in the BDD spec above.Create a class that defines
ShoppingList
.
ShoppingList
will have all the properties and methods defined in the BDD spec above.once all tests pass, commit and push.
Create implementation files.
index.html
shopping_list_item.js
shopping_list.js
app.js
Shopping-List/ node_modules/ mocha/ chai/ js/ shopping_list_test.js shopping_list_item.js shopping_list.js app.js tests.html index.html
Standard html5 document, include a single empty
div
element with an id ofcontent
before the end of this body tag, include your 3 shopping list scripts.Create a form that has 2 text fields,
title
anddescription
.Add a
button
element with the contents of "Add to Shopping List", and give it an id ofadd_shopping_list_item_button
.Add a
click
event handler to theadd_shopping_list_item_button
that will run a function calledadd_to_shopping_list()
. http://www.w3schools.com/jsref/event_onclick.aspCreate an instance of ShoppingList.
Invoke the shopping_list object's render() method, and store the output to a variable. Write the resulting output html into the
content
div. http://www.w3schools.com/jsref/prop_html_innerhtml.aspCreate an
add_shopping_list_item_button
function that will read the value of thetitle
anddescription
fields, then create a new variable namednew_shopping_list_item
that will store the result of constructing a new ShoppingListItem and passing in the values oftitle
anddescription
.Invoke your shopping list's
addItem
by passing in yournew_shopping_list_item
.Re-render the shopping list.
commit and push your work
Modify the ShoppingListItem
render()
method to include acheckbox
input. Add anonchange
event listener to this checkbox that will call a function namedchangeCheckedStatus(idx, checked)
where 'idx' is the position (array index) of the ShoppingListItem, and 'checked' is the value of the checkbox. http://www.w3schools.com/jsref/prop_checkbox_checked.aspcreate a
changeCheckedStatus
function that accepts a single argument, idx.
it will find a ShoppingListItem based on the idx passed in to the function.
determine if the checkbox that has been clicked, is now checked or not checked. http://www.w3schools.com/jsref/event_onchange.asp
if the checkbox is checked, invoke the shopping_list_item object'scheck()
method. if the checkbox is not checked,
invoke the shopping_list_item object'suncheck()
method. then, re-render the shopping list.commit and push your work.
Modify the ShoppingListItem
render()
method to include abutton
element with the labelx
. Add aclick
event listener to this button that will call a function namedremoveItemButtonClicked(idx)
where 'idx' is the position (array index) of the ShoppingListItem.create a
removeItemButtonClicked
function that accepts a single argument, idx.
it will find a ShoppingListItem based on the idx passed in to the function.
it will call the shopping_list instance'sremoveItem
method, while passing in the found ShoppingListItem object as an argument. then, re-render the shopping list.commit and push your work.
- calling the instance's