Skip to content

Commit 2cce636

Browse files
committed
added e2e test for singular / plural units.
1 parent 438b38f commit 2cce636

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

app/js/timer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ angular.module('timer', [])
9898
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
9999
$scope.secondsS = $scope.seconds==1 ? '' : 's';
100100
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
101-
$scope.minutesS = $scope.minutesS==1 ? '' : 's';
101+
$scope.minutesS = $scope.minutes==1 ? '' : 's';
102102
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
103-
$scope.hoursS = $scope.hoursS==1 ? '' : 's';
103+
$scope.hoursS = $scope.hours==1 ? '' : 's';
104104
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
105-
$scope.daysS = $scope.daysS==1 ? '' : 's';
105+
$scope.daysS = $scope.days==1 ? '' : 's';
106106
}
107107

108108
//determine initial values of time units and add AddSeconds functionality

dist/angular-timer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ angular.module('timer', [])
103103

104104
function calculateTimeUnits() {
105105
$scope.seconds = Math.floor(($scope.millis / 1000) % 60);
106+
$scope.secondsS = $scope.seconds==1 ? '' : 's';
106107
$scope.minutes = Math.floor((($scope.millis / (60000)) % 60));
108+
$scope.minutesS = $scope.minutes==1 ? '' : 's';
107109
$scope.hours = Math.floor((($scope.millis / (3600000)) % 24));
110+
$scope.hoursS = $scope.hours==1 ? '' : 's';
108111
$scope.days = Math.floor((($scope.millis / (3600000)) / 24));
112+
$scope.daysS = $scope.days==1 ? '' : 's';
109113
}
110114

111115
//determine initial values of time units and add AddSeconds functionality

dist/angular-timer.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ <h3>
146146
<button class="btn" onclick="stopResumeTimer('auto-start-false-timer', this)" type="button">Start</button>
147147
</div>
148148
</section>
149+
150+
<section id="plural-unit-timer">
151+
<h3>Plural / Singular units</h3>
152+
153+
<div class="bs-docs-example">
154+
<p>
155+
Two stopped countdown timers to illustrate how to handle pluralization of time units.
156+
<code ng-non-bindable="">
157+
&lt;timer autostart="false" countdown="90061"&gt;{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.&lt;/timer&gt;
158+
</code>
159+
160+
<h3 class="singular-counter">
161+
<timer autostart="false" countdown="90061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
162+
</h3>
163+
<h3 class="plural-counter">
164+
<timer autostart="false" countdown="190061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
165+
</h3>
166+
</div>
167+
</section>
168+
149169
<section id="markup">
150170
<h3>
151171
Markup</h3>

test/e2e/scenarios.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,17 @@ describe('Angular Timer E2E Tests', function () {
8585
var afterTime = element('#timer-with-end-time timer span').html();
8686
expect(beforeTime).toHaveMoreSecondsThan(afterTime);
8787
});
88+
89+
it('Plural / Singular Units - Should properly pluralize units', function () {
90+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 day,/);
91+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 hour,/);
92+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 minute,/);
93+
expect(element('#plural-unit-timer .singular-counter timer').html()).toMatch(/1 second/);
94+
95+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/days,/);
96+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/hours,/);
97+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/minutes,/);
98+
expect(element('#plural-unit-timer .plural-counter timer').html()).toMatch(/seconds/);
99+
});
100+
88101
});

0 commit comments

Comments
 (0)