File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,16 @@ angular.module('timer', [])
157
157
$scope . addCDSeconds ( extraSeconds ) ;
158
158
} ) ;
159
159
} ) ;
160
+
161
+ $scope . $on ( 'timer-set-countdown-seconds' , function ( e , countdownSeconds ) {
162
+ if ( ! $scope . isRunning ) {
163
+ $scope . clear ( ) ;
164
+ }
165
+
166
+ $scope . countdown = countdownSeconds ;
167
+ $scope . millis = countdownSeconds * 1000 ;
168
+ calculateTimeUnits ( ) ;
169
+ } ) ;
160
170
} else {
161
171
$scope . millis = 0 ;
162
172
}
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ describe ( 'timer-set-countdown-seconds event handling tests' , function ( ) {
4
+ beforeEach ( module ( 'timer' ) ) ;
5
+
6
+ it ( 'should call the event and set single digit seconds correctly' , function ( ) {
7
+ inject ( function ( $compile , $rootScope , $timeout ) {
8
+ var scope = $rootScope . $new ( ) ;
9
+ var element = $compile ( '<timer countdown="10" interval="1000" autostart="false">{{sseconds}}</timer>' ) ( scope ) ;
10
+ scope . $digest ( ) ;
11
+
12
+ scope . $broadcast ( 'timer-set-countdown-seconds' , 5 ) ;
13
+
14
+ $timeout ( function ( ) {
15
+ scope . $digest ( ) ;
16
+ expect ( element . html ( ) . indexOf ( '05' ) ) . toBeGreaterThan ( - 1 ) ;
17
+ } , 500 ) ;
18
+
19
+ $timeout . flush ( ) ;
20
+ } ) ;
21
+ } ) ;
22
+
23
+ it ( 'should call the event and set larger second values correctly' , function ( ) {
24
+ inject ( function ( $compile , $rootScope , $timeout ) {
25
+ var scope = $rootScope . $new ( ) ;
26
+ var element = $compile ( '<timer countdown="10" interval="1000" autostart="false">{{mminutes}}:{{sseconds}}</timer>' ) ( scope ) ;
27
+ scope . $digest ( ) ;
28
+
29
+ scope . $broadcast ( 'timer-set-countdown-seconds' , 135 ) ;
30
+
31
+ $timeout ( function ( ) {
32
+ scope . $digest ( ) ;
33
+ expect ( element . html ( ) . indexOf ( '02:15' ) ) . toBeGreaterThan ( - 1 ) ;
34
+ } , 500 ) ;
35
+
36
+ $timeout . flush ( ) ;
37
+ } ) ;
38
+ } ) ;
39
+ } ) ;
You can’t perform that action at this time.
0 commit comments