Skip to content

Commit

Permalink
add e2e test for leading zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanja Stier authored and Wanja Stier committed Mar 18, 2014
1 parent 3cab94c commit d227f8e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
14 changes: 5 additions & 9 deletions app/js/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ angular.module('timer', [])
startTimeAttr: '=startTime',
endTimeAttr: '=endTime',
countdownattr: '=countdown',

autoStart: '&autoStart'
},
controller: ['$scope', '$element', '$attrs', '$timeout', function ($scope, $element, $attrs, $timeout) {
Expand All @@ -18,8 +17,6 @@ angular.module('timer', [])
//backward and forward compatibility.
$scope.autoStart = $attrs.autoStart || $attrs.autostart;

$scope.addLeadingZero = ($attrs.$attr.addLeadingZero || $attrs.$attr.addleadingzero ) ? true : false;

if ($element.html().trim().length === 0) {
$element.append($compile('<span>{{millis}}</span>')($scope));
} else {
Expand Down Expand Up @@ -103,13 +100,12 @@ angular.module('timer', [])
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));

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

if($scope.addLeadingZero){
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
}
}
//determine initial values of time units and add AddSeconds functionality
if ($scope.countdownattr) {
Expand Down
17 changes: 7 additions & 10 deletions dist/angular-timer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* angular-timer - v1.0.12 - 2014-03-18 2:51 PM
* angular-timer - v1.0.12 - 2014-03-18 4:02 PM
* https://github.com/siddii/angular-timer
*
* Copyright (c) 2014 Siddique Hameed
Expand All @@ -15,7 +15,6 @@ angular.module('timer', [])
startTimeAttr: '=startTime',
endTimeAttr: '=endTime',
countdownattr: '=countdown',

autoStart: '&autoStart'
},
controller: ['$scope', '$element', '$attrs', '$timeout', function ($scope, $element, $attrs, $timeout) {
Expand All @@ -25,8 +24,6 @@ angular.module('timer', [])
//backward and forward compatibility.
$scope.autoStart = $attrs.autoStart || $attrs.autostart;

$scope.addLeadingZero = ($attrs.$attr.addLeadingZero || $attrs.$attr.addleadingzero ) ? true : false;

if ($element.html().trim().length === 0) {
$element.append($compile('<span>{{millis}}</span>')($scope));
} else {
Expand Down Expand Up @@ -110,12 +107,12 @@ angular.module('timer', [])
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));

if($scope.addLeadingZero){
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;
}
//add leading zero if number is smaller than 10
$scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;
$scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;
$scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;
$scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;

}
//determine initial values of time units and add AddSeconds functionality
if ($scope.countdownattr) {
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-timer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ <h3>

<div class="bs-docs-example">
<p>
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot; add-leading-zero&gt;{{hours}} hours, {{minutes}}
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>
This markup <code ng-non-bindable="">&lt;timer interval=&quot;1000&quot;&gt;{{hhours}} hours, {{mminutes}}
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>

<h3>
<timer interval="1000" add-leading-zero>{{hhours}} hours, {{mminutes}} minutes, {{sseconds}} seconds.</timer>
<timer interval="1000">{{hhours}} hours, {{mminutes}} minutes, {{sseconds}} seconds.</timer>
</h3>
<button class="btn" onclick="stopResumeTimer('clock-timer', this)" type="button">Stop</button>
</div>
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Angular Timer E2E Tests', function () {
}
});


it("Simple Timer - Should stop ticking when user clicks 'Stop' button", function () {
sleep(1);
element('#basic-timer button:last-child').click();
Expand Down Expand Up @@ -85,4 +86,16 @@ describe('Angular Timer E2E Tests', function () {
var afterTime = element('#timer-with-end-time timer span').html();
expect(beforeTime).toHaveMoreSecondsThan(afterTime);
});

it('Leading zero timer - should add a leading zero if number is smaller than 10', function() {
sleep(1);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/01 seconds./);
sleep(10);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 hours,/);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/00 minutes,/);
expect(element('#clock-timer-leading-zero timer').html()).toMatch(/11 seconds./);
});

});

0 comments on commit d227f8e

Please sign in to comment.