Skip to content

Commit

Permalink
added e2e test for singular / plural units.
Browse files Browse the repository at this point in the history
  • Loading branch information
itslenny committed Mar 18, 2014
1 parent 438b38f commit 2cce636
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/js/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ angular.module('timer', [])
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
$scope.secondsS = $scope.seconds==1 ? '' : 's';
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
$scope.minutesS = $scope.minutesS==1 ? '' : 's';
$scope.minutesS = $scope.minutes==1 ? '' : 's';
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
$scope.hoursS = $scope.hoursS==1 ? '' : 's';
$scope.hoursS = $scope.hours==1 ? '' : 's';
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
$scope.daysS = $scope.daysS==1 ? '' : 's';
$scope.daysS = $scope.days==1 ? '' : 's';
}

//determine initial values of time units and add AddSeconds functionality
Expand Down
4 changes: 4 additions & 0 deletions dist/angular-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ angular.module('timer', [])

function calculateTimeUnits() {
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
$scope.secondsS = $scope.seconds==1 ? '' : 's';
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
$scope.minutesS = $scope.minutes==1 ? '' : 's';
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
$scope.hoursS = $scope.hours==1 ? '' : 's';
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
$scope.daysS = $scope.days==1 ? '' : 's';
}

//determine initial values of time units and add AddSeconds functionality
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-timer.min.js

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

20 changes: 20 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ <h3>
<button class="btn" onclick="stopResumeTimer('auto-start-false-timer', this)" type="button">Start</button>
</div>
</section>

<section id="plural-unit-timer">
<h3>Plural / Singular units</h3>

<div class="bs-docs-example">
<p>
Two stopped countdown timers to illustrate how to handle pluralization of time units.
<code ng-non-bindable="">
&lt;timer autostart="false" countdown="90061"&gt;{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.&lt;/timer&gt;
</code>

<h3 class="singular-counter">
<timer autostart="false" countdown="90061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
</h3>
<h3 class="plural-counter">
<timer autostart="false" countdown="190061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
</h3>
</div>
</section>

<section id="markup">
<h3>
Markup</h3>
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,17 @@ describe('Angular Timer E2E Tests', function () {
var afterTime = element('#timer-with-end-time timer span').html();
expect(beforeTime).toHaveMoreSecondsThan(afterTime);
});

it('Plural / Singular Units - Should properly pluralize units', function () {
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 day,/);
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 hour,/);
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 minute,/);
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 second/);

expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/days,/);
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/hours,/);
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/minutes,/);
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/seconds/);
});

});

0 comments on commit 2cce636

Please sign in to comment.