From e1893fafd3445fc17c9a1036736c47cf8d4bdcab Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 30 Apr 2014 00:26:55 -0500 Subject: [PATCH 1/2] Added handling to allow just setting countdown timer value. The "timer-set-countdown-seconds" event allows the user to set the value the countdown timer will start from, without immediately starting the clock going. --- app/js/timer.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/js/timer.js b/app/js/timer.js index 617f34f..65cbbf0 100644 --- a/app/js/timer.js +++ b/app/js/timer.js @@ -157,6 +157,16 @@ angular.module('timer', []) $scope.addCDSeconds(extraSeconds); }); }); + + $scope.$on('timer-set-countdown-seconds', function(e, countdownSeconds) { + if (!$scope.isRunning) { + $scope.clear(); + } + + $scope.countdown = countdownSeconds; + $scope.millis = countdownSeconds * 1000; + calculateTimeUnits(); + }); } else { $scope.millis = 0; } From fd24d844cc6da800a5436d542f54e96521ccea80 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 1 May 2014 22:02:12 -0500 Subject: [PATCH 2/2] Added a couple of unit tests around new countdown timer setting event. --- test/unit/timerSetTimeTest.js | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/unit/timerSetTimeTest.js diff --git a/test/unit/timerSetTimeTest.js b/test/unit/timerSetTimeTest.js new file mode 100644 index 0000000..cfabf7e --- /dev/null +++ b/test/unit/timerSetTimeTest.js @@ -0,0 +1,39 @@ +'use strict'; + +describe('timer-set-countdown-seconds event handling tests', function () { + beforeEach(module('timer')); + + it('should call the event and set single digit seconds correctly', function () { + inject(function ($compile, $rootScope, $timeout) { + var scope = $rootScope.$new(); + var element = $compile('{{sseconds}}')(scope); + scope.$digest(); + + scope.$broadcast('timer-set-countdown-seconds', 5); + + $timeout(function () { + scope.$digest(); + expect(element.html().indexOf('05')).toBeGreaterThan(-1); + }, 500); + + $timeout.flush(); + }); + }); + + it('should call the event and set larger second values correctly', function () { + inject(function ($compile, $rootScope, $timeout) { + var scope = $rootScope.$new(); + var element = $compile('{{mminutes}}:{{sseconds}}')(scope); + scope.$digest(); + + scope.$broadcast('timer-set-countdown-seconds', 135); + + $timeout(function () { + scope.$digest(); + expect(element.html().indexOf('02:15')).toBeGreaterThan(-1); + }, 500); + + $timeout.flush(); + }); + }); +}); \ No newline at end of file