Skip to content

Commit d227f8e

Browse files
Wanja StierWanja Stier
Wanja Stier
authored and
Wanja Stier
committed
add e2e test for leading zero
1 parent 3cab94c commit d227f8e

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

app/js/timer.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ angular.module('timer', [])
88
startTimeAttr: '=startTime',
99
endTimeAttr: '=endTime',
1010
countdownattr: '=countdown',
11-
1211
autoStart: '&autoStart'
1312
},
1413
controller: ['$scope', '$element', '$attrs', '$timeout', function ($scope, $element, $attrs, $timeout) {
@@ -18,8 +17,6 @@ angular.module('timer', [])
1817
//backward and forward compatibility.
1918
$scope.autoStart = $attrs.autoStart || $attrs.autostart;
2019

21-
$scope.addLeadingZero = ($attrs.$attr.addLeadingZero || $attrs.$attr.addleadingzero ) ? true : false;
22-
2320
if ($element.html().trim().length === 0) {
2421
$element.append($compile('<span>{{millis}}</span>')($scope));
2522
} else {
@@ -103,13 +100,12 @@ angular.module('timer', [])
103100
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
104101
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
105102

103+
//add leading zero if number is smaller than 10
104+
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
105+
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
106+
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
107+
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
106108

107-
if($scope.addLeadingZero){
108-
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
109-
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
110-
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
111-
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
112-
}
113109
}
114110
//determine initial values of time units and add AddSeconds functionality
115111
if ($scope.countdownattr) {

dist/angular-timer.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* angular-timer - v1.0.12 - 2014-03-18 2:51 PM
2+
* angular-timer - v1.0.12 - 2014-03-18 4:02 PM
33
* https://github.com/siddii/angular-timer
44
*
55
* Copyright (c) 2014 Siddique Hameed
@@ -15,7 +15,6 @@ angular.module('timer', [])
1515
startTimeAttr: '=startTime',
1616
endTimeAttr: '=endTime',
1717
countdownattr: '=countdown',
18-
1918
autoStart: '&autoStart'
2019
},
2120
controller: ['$scope', '$element', '$attrs', '$timeout', function ($scope, $element, $attrs, $timeout) {
@@ -25,8 +24,6 @@ angular.module('timer', [])
2524
//backward and forward compatibility.
2625
$scope.autoStart = $attrs.autoStart || $attrs.autostart;
2726

28-
$scope.addLeadingZero = ($attrs.$attr.addLeadingZero || $attrs.$attr.addleadingzero ) ? true : false;
29-
3027
if ($element.html().trim().length === 0) {
3128
$element.append($compile('<span>{{millis}}</span>')($scope));
3229
} else {
@@ -110,12 +107,12 @@ angular.module('timer', [])
110107
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
111108
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
112109

113-
if($scope.addLeadingZero){
114-
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
115-
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
116-
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
117-
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
118-
}
110+
//add leading zero if number is smaller than 10
111+
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
112+
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
113+
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
114+
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
115+
119116
}
120117
//determine initial values of time units and add AddSeconds functionality
121118
if ($scope.countdownattr) {

dist/angular-timer.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ <h3>
7070

7171
<div class="bs-docs-example">
7272
<p>
73-
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot; add-leading-zero&gt;{{hours}} hours, {{minutes}}
74-
minutes, {{seconds}} seconds.&lt;/timer&gt;</code> will run the clock timer ticking every second with an additional zero at the beginning if unit is smaller than 10</p>
73+
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot;&gt;{{hhours}} hours, {{mminutes}}
74+
minutes, {{sseconds}} seconds.&lt;/timer&gt;</code> will run the clock timer ticking every second with an additional zero at the beginning if unit is smaller than 10</p>
7575

7676
<h3>
77-
<timer interval="1000" add-leading-zero>{{hhours}} hours, {{mminutes}} minutes, {{sseconds}} seconds.</timer>
77+
<timer interval="1000">{{hhours}} hours, {{mminutes}} minutes, {{sseconds}} seconds.</timer>
7878
</h3>
7979
<button class="btn" onclick="stopResumeTimer('clock-timer', this)" type="button">Stop</button>
8080
</div>

test/e2e/scenarios.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe('Angular Timer E2E Tests', function () {
3232
}
3333
});
3434

35+
3536
it("Simple Timer - Should stop ticking when user clicks 'Stop' button", function () {
3637
sleep(1);
3738
element('#basic-timer button:last-child').click();
@@ -85,4 +86,16 @@ describe('Angular Timer E2E Tests', function () {
8586
var afterTime = element('#timer-with-end-time timer span').html();
8687
expect(beforeTime).toHaveMoreSecondsThan(afterTime);
8788
});
89+
90+
it('Leading zero timer - should add a leading zero if number is smaller than 10', function() {
91+
sleep(1);
92+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
93+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
94+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/01 seconds./);
95+
sleep(10);
96+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
97+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
98+
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/11 seconds./);
99+
});
100+
88101
});

0 commit comments

Comments
 (0)