1
1
'use strict' ;
2
2
3
3
describe ( 'ngPluralize' , function ( ) {
4
- var element ;
4
+ var element ,
5
+ elementAlt ;
5
6
6
7
7
8
afterEach ( function ( ) {
8
9
dealoc ( element ) ;
10
+ dealoc ( elementAlt ) ;
9
11
} ) ;
10
12
11
13
12
14
describe ( 'deal with pluralized strings without offset' , function ( ) {
13
15
beforeEach ( inject ( function ( $rootScope , $compile ) {
14
16
element = $compile (
15
17
'<ng:pluralize count="email"' +
16
- "when=\"{'0': 'You have no new email'," +
18
+ "when=\"{'-1': 'You have negative email. Whohoo!'," +
19
+ "'0': 'You have no new email'," +
17
20
"'one': 'You have one new email'," +
18
21
"'other': 'You have {} new emails'}\">" +
19
22
'</ng:pluralize>' ) ( $rootScope ) ;
23
+ elementAlt = $compile (
24
+ '<ng:pluralize count="email" ' +
25
+ "when-minus-1='You have negative email. Whohoo!' " +
26
+ "when-0='You have no new email' " +
27
+ "when-one='You have one new email' " +
28
+ "when-other='You have {} new emails'>" +
29
+ '</ng:pluralize>' ) ( $rootScope ) ;
20
30
} ) ) ;
21
31
22
32
23
33
it ( 'should show single/plural strings' , inject ( function ( $rootScope ) {
24
34
$rootScope . email = 0 ;
25
35
$rootScope . $digest ( ) ;
26
36
expect ( element . text ( ) ) . toBe ( 'You have no new email' ) ;
37
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have no new email' ) ;
27
38
28
39
$rootScope . email = '0' ;
29
40
$rootScope . $digest ( ) ;
30
41
expect ( element . text ( ) ) . toBe ( 'You have no new email' ) ;
42
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have no new email' ) ;
31
43
32
44
$rootScope . email = 1 ;
33
45
$rootScope . $digest ( ) ;
34
46
expect ( element . text ( ) ) . toBe ( 'You have one new email' ) ;
47
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have one new email' ) ;
35
48
36
49
$rootScope . email = 0.01 ;
37
50
$rootScope . $digest ( ) ;
38
51
expect ( element . text ( ) ) . toBe ( 'You have 0.01 new emails' ) ;
52
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have 0.01 new emails' ) ;
39
53
40
54
$rootScope . email = '0.1' ;
41
55
$rootScope . $digest ( ) ;
42
56
expect ( element . text ( ) ) . toBe ( 'You have 0.1 new emails' ) ;
57
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have 0.1 new emails' ) ;
43
58
44
59
$rootScope . email = 2 ;
45
60
$rootScope . $digest ( ) ;
46
61
expect ( element . text ( ) ) . toBe ( 'You have 2 new emails' ) ;
62
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have 2 new emails' ) ;
47
63
48
64
$rootScope . email = - 0.1 ;
49
65
$rootScope . $digest ( ) ;
50
66
expect ( element . text ( ) ) . toBe ( 'You have -0.1 new emails' ) ;
67
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have -0.1 new emails' ) ;
51
68
52
69
$rootScope . email = '-0.01' ;
53
70
$rootScope . $digest ( ) ;
54
71
expect ( element . text ( ) ) . toBe ( 'You have -0.01 new emails' ) ;
72
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have -0.01 new emails' ) ;
55
73
56
74
$rootScope . email = - 2 ;
57
75
$rootScope . $digest ( ) ;
58
76
expect ( element . text ( ) ) . toBe ( 'You have -2 new emails' ) ;
77
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have -2 new emails' ) ;
78
+
79
+ $rootScope . email = - 1 ;
80
+ $rootScope . $digest ( ) ;
81
+ expect ( element . text ( ) ) . toBe ( 'You have negative email. Whohoo!' ) ;
82
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have negative email. Whohoo!' ) ;
59
83
} ) ) ;
60
84
61
85
62
86
it ( 'should show single/plural strings with mal-formed inputs' , inject ( function ( $rootScope ) {
63
87
$rootScope . email = '' ;
64
88
$rootScope . $digest ( ) ;
65
89
expect ( element . text ( ) ) . toBe ( '' ) ;
90
+ expect ( elementAlt . text ( ) ) . toBe ( '' ) ;
66
91
67
92
$rootScope . email = null ;
68
93
$rootScope . $digest ( ) ;
69
94
expect ( element . text ( ) ) . toBe ( '' ) ;
95
+ expect ( elementAlt . text ( ) ) . toBe ( '' ) ;
70
96
71
97
$rootScope . email = undefined ;
72
98
$rootScope . $digest ( ) ;
73
99
expect ( element . text ( ) ) . toBe ( '' ) ;
100
+ expect ( elementAlt . text ( ) ) . toBe ( '' ) ;
74
101
75
102
$rootScope . email = 'a3' ;
76
103
$rootScope . $digest ( ) ;
77
104
expect ( element . text ( ) ) . toBe ( '' ) ;
105
+ expect ( elementAlt . text ( ) ) . toBe ( '' ) ;
78
106
79
107
$rootScope . email = '011' ;
80
108
$rootScope . $digest ( ) ;
81
109
expect ( element . text ( ) ) . toBe ( 'You have 11 new emails' ) ;
110
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have 11 new emails' ) ;
82
111
83
112
$rootScope . email = '-011' ;
84
113
$rootScope . $digest ( ) ;
85
114
expect ( element . text ( ) ) . toBe ( 'You have -11 new emails' ) ;
115
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have -11 new emails' ) ;
86
116
87
117
$rootScope . email = '1fff' ;
88
118
$rootScope . $digest ( ) ;
89
119
expect ( element . text ( ) ) . toBe ( 'You have one new email' ) ;
120
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have one new email' ) ;
90
121
91
122
$rootScope . email = '0aa22' ;
92
123
$rootScope . $digest ( ) ;
93
124
expect ( element . text ( ) ) . toBe ( 'You have no new email' ) ;
125
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have no new email' ) ;
94
126
95
127
$rootScope . email = '000001' ;
96
128
$rootScope . $digest ( ) ;
97
129
expect ( element . text ( ) ) . toBe ( 'You have one new email' ) ;
130
+ expect ( elementAlt . text ( ) ) . toBe ( 'You have one new email' ) ;
98
131
} ) ) ;
99
132
} ) ;
100
133
@@ -117,35 +150,48 @@ describe('ngPluralize', function() {
117
150
describe ( 'deal with pluralized strings with offset' , function ( ) {
118
151
it ( 'should show single/plural strings with offset' , inject ( function ( $rootScope , $compile ) {
119
152
element = $compile (
120
- "<ng:pluralize count=\" viewCount\" offset=2 " +
153
+ "<ng:pluralize count=' viewCount' offset='2' " +
121
154
"when=\"{'0': 'Nobody is viewing.'," +
122
155
"'1': '{{p1}} is viewing.'," +
123
156
"'2': '{{p1}} and {{p2}} are viewing.'," +
124
157
"'one': '{{p1}}, {{p2}} and one other person are viewing.'," +
125
158
"'other': '{{p1}}, {{p2}} and {} other people are viewing.'}\">" +
126
159
"</ng:pluralize>" ) ( $rootScope ) ;
160
+ elementAlt = $compile (
161
+ "<ng:pluralize count='viewCount' offset='2' " +
162
+ "when-0='Nobody is viewing.'" +
163
+ "when-1='{{p1}} is viewing.'" +
164
+ "when-2='{{p1}} and {{p2}} are viewing.'" +
165
+ "when-one='{{p1}}, {{p2}} and one other person are viewing.'" +
166
+ "when-other='{{p1}}, {{p2}} and {} other people are viewing.'>" +
167
+ "</ng:pluralize>" ) ( $rootScope ) ;
127
168
$rootScope . p1 = 'Igor' ;
128
169
$rootScope . p2 = 'Misko' ;
129
170
130
171
$rootScope . viewCount = 0 ;
131
172
$rootScope . $digest ( ) ;
132
173
expect ( element . text ( ) ) . toBe ( 'Nobody is viewing.' ) ;
174
+ expect ( elementAlt . text ( ) ) . toBe ( 'Nobody is viewing.' ) ;
133
175
134
176
$rootScope . viewCount = 1 ;
135
177
$rootScope . $digest ( ) ;
136
178
expect ( element . text ( ) ) . toBe ( 'Igor is viewing.' ) ;
179
+ expect ( elementAlt . text ( ) ) . toBe ( 'Igor is viewing.' ) ;
137
180
138
181
$rootScope . viewCount = 2 ;
139
182
$rootScope . $digest ( ) ;
140
183
expect ( element . text ( ) ) . toBe ( 'Igor and Misko are viewing.' ) ;
184
+ expect ( elementAlt . text ( ) ) . toBe ( 'Igor and Misko are viewing.' ) ;
141
185
142
186
$rootScope . viewCount = 3 ;
143
187
$rootScope . $digest ( ) ;
144
188
expect ( element . text ( ) ) . toBe ( 'Igor, Misko and one other person are viewing.' ) ;
189
+ expect ( elementAlt . text ( ) ) . toBe ( 'Igor, Misko and one other person are viewing.' ) ;
145
190
146
191
$rootScope . viewCount = 4 ;
147
192
$rootScope . $digest ( ) ;
148
193
expect ( element . text ( ) ) . toBe ( 'Igor, Misko and 2 other people are viewing.' ) ;
194
+ expect ( elementAlt . text ( ) ) . toBe ( 'Igor, Misko and 2 other people are viewing.' ) ;
149
195
} ) ) ;
150
196
} ) ;
151
197
@@ -165,23 +211,34 @@ describe('ngPluralize', function() {
165
211
"'one': '[[p1%% and one other person are viewing.'," +
166
212
"'other': '[[p1%% and {} other people are viewing.'}\">" +
167
213
"</ng:pluralize>" ) ( $rootScope ) ;
214
+ elementAlt = $compile (
215
+ "<ng:pluralize count='viewCount' offset='1'" +
216
+ "when-0='Nobody is viewing.'" +
217
+ "when-1='[[p1%% is viewing.'" +
218
+ "when-one='[[p1%% and one other person are viewing.'" +
219
+ "when-other='[[p1%% and {} other people are viewing.'>" +
220
+ "</ng:pluralize>" ) ( $rootScope ) ;
168
221
$rootScope . p1 = 'Igor' ;
169
222
170
223
$rootScope . viewCount = 0 ;
171
224
$rootScope . $digest ( ) ;
172
225
expect ( element . text ( ) ) . toBe ( 'Nobody is viewing.' ) ;
226
+ expect ( elementAlt . text ( ) ) . toBe ( 'Nobody is viewing.' ) ;
173
227
174
228
$rootScope . viewCount = 1 ;
175
229
$rootScope . $digest ( ) ;
176
230
expect ( element . text ( ) ) . toBe ( 'Igor is viewing.' ) ;
231
+ expect ( elementAlt . text ( ) ) . toBe ( 'Igor is viewing.' ) ;
177
232
178
233
$rootScope . viewCount = 2 ;
179
234
$rootScope . $digest ( ) ;
180
235
expect ( element . text ( ) ) . toBe ( 'Igor and one other person are viewing.' ) ;
236
+ expect ( elementAlt . text ( ) ) . toBe ( 'Igor and one other person are viewing.' ) ;
181
237
182
238
$rootScope . viewCount = 3 ;
183
239
$rootScope . $digest ( ) ;
184
240
expect ( element . text ( ) ) . toBe ( 'Igor and 2 other people are viewing.' ) ;
241
+ expect ( elementAlt . text ( ) ) . toBe ( 'Igor and 2 other people are viewing.' ) ;
185
242
} ) ;
186
243
} )
187
244
} ) ;
0 commit comments