Add support for JavaScript unit and end-to-end testing

There is a lot of JS code that makes changes to the data and to the DOM that isn't being tested right now.

For the test configuration and runner I would suggest the excellent [Testacular] (http://testacular.github.com/0.6.0/index.html). This allows for configuring and running unit and end-2-end tests in a headless WebKit browser ([PhantomJS](http://phantomjs.org)), and [Jasmine](http://pivotal.github.com/jasmine) as the test framework (this is the default in [Testacular] (http://testacular.github.com/0.6.0/index.html).)

Edit: Using Testacular and PhantomJS will introduce a dependency on NodeJS and for PhantomJS to be installed system-wide. It's easy enough to configure the test suite to skip JS tests with a warning when deps are not installed, to avoid _requiring_ people to have these installed. TravisCI has PhantomJS installed by default, and I believe also NodeJS, so no issues there.