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;
}
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