Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion app/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ <h4>Alarm at {{ alarm.value | clockDisplay }}</h4>
</div>
</body>

</html>
</html>
5 changes: 3 additions & 2 deletions app/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
)
Expand Down
65 changes: 65 additions & 0 deletions app/static/tests/clock-tests.js
Original file line number Diff line number Diff line change
@@ -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('<span datetime-picker ng-model="clock.newAlarm"></span>')(scope)
scope.$digest();
console.log(element);
console.log(element.find('label'));
console.log(element.find('clock.newAlarm'));
console.log(element.find('applytime'));


});
});