diff --git a/README.md b/README.md index 15bb1f0..e4d6551 100644 --- a/README.md +++ b/README.md @@ -79,4 +79,4 @@ The following pages are useful introductions to testing in AngularJS. - [Angular tips](http://angular-tips.com/blog/categories/unit-test/) - [Angular Recipes](http://fdietz.github.io/recipes-with-angular-js/directives/testing-directives.html) - [ng-newsletter](http://www.ng-newsletter.com/advent2013/#!/day/19) -- [Core Angular Docs](https://docs.angularjs.org/guide/unit-testing) +- [Core Angular Docs](https://docs.angularjs.org/guide/unit-testing) \ No newline at end of file diff --git a/app/static/index.html b/app/static/index.html index be4712d..174dcdc 100644 --- a/app/static/index.html +++ b/app/static/index.html @@ -51,4 +51,4 @@

Alarm at {{ alarm.value | clockDisplay }}

- + \ No newline at end of file diff --git a/app/static/js/app.js b/app/static/js/app.js index f87660f..e2be5f4 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -12,7 +12,6 @@ angular.module('JobDashClock', ['ngMaterial']) var self = this; self.time = "Loading ..."; self.tickInterval = 1000; // ms - self.tick = function() { self.time = moment() // get the current time $timeout(self.tick, self.tickInterval); // reset the timer @@ -24,6 +23,7 @@ angular.module('JobDashClock', ['ngMaterial']) self.alarms = []; self.newAlarm = new Date(); + self.alarmTest = false; self.addAlarm = function () { var alarm = moment(self.newAlarm); @@ -32,7 +32,8 @@ angular.module('JobDashClock', ['ngMaterial']) if (moment().isBefore(alarm)) { alertTimer = $timeout( function() { - alert('Alarm!') + alert('Alarm!'); + self.alarmTest = true; }, alarm.diff(moment()) // ms between the alarm time and now ) diff --git a/app/static/tests/clock-tests.js b/app/static/tests/clock-tests.js new file mode 100644 index 0000000..72dc88d --- /dev/null +++ b/app/static/tests/clock-tests.js @@ -0,0 +1,65 @@ +describe('controller: TimeCtrl', function(){ + + beforeEach(module('JobDashClock')); + + it('should create an alarm that will activate in two seconds and then remove said alarm', inject(function($controller) { + var scope = {}, + ctrl = new $controller('TimeCtrl', {$scope:scope}); + // testAlarm = new Date(); + testTime = moment(); + ctrl.newAlarm = moment(); + ctrl.newAlarm.add(2, 'seconds'); //creates an alarm that will activate two seconds after creation + ctrl.addAlarm(); + expect(ctrl.alarms[0].value.format()).toBe(testTime.add(2, 'seconds').format()) + setTimeout(function() { expect(ctrl.newAlarm).toBe(true); }, 2010); //tests to see if the alarm has activated after two seconds. + })) +}) + + +describe('filter: clockDisplay', function() { + + beforeEach(module('JobDashClock')); + + beforeEach(inject(function(_clockDisplayFilter_) { + clockDisplayFilter = _clockDisplayFilter_; + })) + + it('should create a formatted string from a date or moment object', function() { + + // if the value is a string, it should be unchanged + expect(clockDisplayFilter('February 8th 2013, 9:30:00 am')).toBe('February 8th 2013, 9:30:00 am'); + + // if the value is a Moment object, it should return a formated string + expect(clockDisplayFilter(moment('2013-02-08 09:30'))).toBe('February 8th 2013, 9:30:00 am'); + + // if the value is a Date object, it should return a formated string + var testTime = new Date(2013, 01, 08, 9, 30); + expect(clockDisplayFilter(testTime)).toBe('February 8th 2013, 9:30:00 am'); + + }) +}) + + +describe('directive: datetimePicker', function() { + + beforeEach(module('JobDashClock')); + + beforeEach(inject(function(_$rootScope_, _$compile_, _$httpBackend_) { + $rootScope = _$rootScope_; + $compile = _$compile_; + $httpBackend = _$httpBackend_; + scope = $rootScope; + })); + + it('should fill the date form with the current date', function() { + $httpBackend.when('GET', '/static/partials/datetime-picker.html').respond('yes'); + element = $compile('')(scope) + scope.$digest(); + console.log(element); + console.log(element.find('label')); + console.log(element.find('clock.newAlarm')); + console.log(element.find('applytime')); + + + }); +});