OLD | NEW |
1 library ng_pluralize_spec; | 1 library ng_pluralize_spec; |
2 | 2 |
3 import '../_specs.dart'; | 3 import '../_specs.dart'; |
4 | 4 |
5 main() { | 5 main() { |
6 describe('PluralizeDirective', () { | 6 describe('PluralizeDirective', () { |
7 | 7 |
8 describe('deal with pluralized strings without offset', () { | 8 describe('deal with pluralized strings without offset', () { |
9 var element; | 9 var element; |
10 var elementAlt; | 10 var elementAlt; |
11 var elt; | 11 var elt; |
12 TestBed _; | 12 TestBed _; |
13 | 13 |
14 beforeEach(inject((TestBed tb) { | 14 beforeEach((TestBed tb) { |
15 _ = tb; | 15 _ = tb; |
16 | 16 |
17 element = _.compile( | 17 element = _.compile( |
18 '<ng-pluralize count="email"' + | 18 '<ng-pluralize count="email"' + |
19 "when=\"{'-1': 'You have negative email. Whohoo!'," + | 19 "when=\"{'-1': 'You have negative email. Whohoo!'," + |
20 "'0': 'You have no new email'," + | 20 "'0': 'You have no new email'," + |
21 "'one': 'You have one new email'," + | 21 "'one': 'You have one new email'," + |
22 "'other': 'You have {} new emails'}\">" + | 22 "'other': 'You have {} new emails'}\">" + |
23 '</ng-pluralize>' | 23 '</ng-pluralize>' |
24 ); | 24 ); |
25 | 25 |
26 elementAlt = _.compile( | 26 elementAlt = _.compile( |
27 '<p ng-pluralize count="email" ' + | 27 '<p ng-pluralize count="email" ' + |
28 "when-minus-1='You have negative email. Whohoo!' " + | 28 "when-minus-1='You have negative email. Whohoo!' " + |
29 "when-0='You have no new email' " + | 29 "when-0='You have no new email' " + |
30 "when-one='You have one new email' " + | 30 "when-one='You have one new email' " + |
31 "when-other='You have {} new emails'>" + | 31 "when-other='You have {} new emails'>" + |
32 '</p>' | 32 '</p>' |
33 ); | 33 ); |
34 })); | 34 }); |
35 | 35 |
36 it('should show single/plural strings', () { | 36 it('should show single/plural strings', () { |
37 _.rootScope.context['email'] = '0'; | 37 _.rootScope.context['email'] = '0'; |
38 _.rootScope.apply(); | 38 _.rootScope.apply(); |
39 expect(element.text).toEqual('You have no new email'); | 39 expect(element.text).toEqual('You have no new email'); |
40 expect(elementAlt.text).toEqual('You have no new email'); | 40 expect(elementAlt.text).toEqual('You have no new email'); |
41 | 41 |
42 _.rootScope.context['email'] = '0'; | 42 _.rootScope.context['email'] = '0'; |
43 _.rootScope.apply(); | 43 _.rootScope.apply(); |
44 expect(element.text).toEqual('You have no new email'); | 44 expect(element.text).toEqual('You have no new email'); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 expect(elementAlt.text).toEqual(''); | 122 expect(elementAlt.text).toEqual(''); |
123 | 123 |
124 _.rootScope.context['email'] = '000001'; | 124 _.rootScope.context['email'] = '000001'; |
125 _.rootScope.apply(); | 125 _.rootScope.apply(); |
126 expect(element.text).toEqual('You have one new email'); | 126 expect(element.text).toEqual('You have one new email'); |
127 expect(elementAlt.text).toEqual('You have one new email'); | 127 expect(elementAlt.text).toEqual('You have one new email'); |
128 }); | 128 }); |
129 }); | 129 }); |
130 | 130 |
131 describe('edge cases', () { | 131 describe('edge cases', () { |
132 it('should be able to handle empty strings as possible values', (inject((T
estBed _) { | 132 it('should be able to handle empty strings as possible values', ((TestBed
_) { |
133 var element = _.compile( | 133 var element = _.compile( |
134 '<ng-pluralize count="email"' + | 134 '<ng-pluralize count="email"' + |
135 "when=\"{'0': ''," + | 135 "when=\"{'0': ''," + |
136 "'one': 'Some text'," + | 136 "'one': 'Some text'," + |
137 "'other': 'Some text'}\">" + | 137 "'other': 'Some text'}\">" + |
138 '</ng-pluralize>'); | 138 '</ng-pluralize>'); |
139 _.rootScope.context['email'] = '0'; | 139 _.rootScope.context['email'] = '0'; |
140 _.rootScope.apply(); | 140 _.rootScope.apply(); |
141 expect(element.text).toEqual(''); | 141 expect(element.text).toEqual(''); |
142 }))); | 142 })); |
143 }); | 143 }); |
144 | 144 |
145 describe('deal with pluralized strings with offset', () { | 145 describe('deal with pluralized strings with offset', () { |
146 it('should show single/plural strings with offset', (inject((TestBed _) { | 146 it('should show single/plural strings with offset', ((TestBed _) { |
147 var element = _.compile( | 147 var element = _.compile( |
148 "<ng-pluralize count='viewCount' offset='2' " + | 148 "<ng-pluralize count='viewCount' offset='2' " + |
149 "when=\"{'0': 'Nobody is viewing.'," + | 149 "when=\"{'0': 'Nobody is viewing.'," + |
150 "'1': '\${p1} is viewing.'," + | 150 "'1': '\${p1} is viewing.'," + |
151 "'2': '\${p1} and \${p2} are viewing.'," + | 151 "'2': '\${p1} and \${p2} are viewing.'," + |
152 "'one': '\${p1}, \${p2} and one other person are viewing.'," + | 152 "'one': '\${p1}, \${p2} and one other person are viewing.'," + |
153 "'other': '\${p1}, \${p2} and {} other people are viewing.'}\">"
+ | 153 "'other': '\${p1}, \${p2} and {} other people are viewing.'}\">"
+ |
154 "</ng-pluralize>"); | 154 "</ng-pluralize>"); |
155 var elementAlt = _.compile( | 155 var elementAlt = _.compile( |
156 "<ng-pluralize count='viewCount' offset='2' " + | 156 "<ng-pluralize count='viewCount' offset='2' " + |
(...skipping 23 matching lines...) Expand all Loading... |
180 | 180 |
181 _.rootScope.context['viewCount'] = 3; | 181 _.rootScope.context['viewCount'] = 3; |
182 _.rootScope.apply(); | 182 _.rootScope.apply(); |
183 expect(element.text).toEqual('Igor, Misko and one other person are viewi
ng.'); | 183 expect(element.text).toEqual('Igor, Misko and one other person are viewi
ng.'); |
184 expect(elementAlt.text).toEqual('Igor, Misko and one other person are vi
ewing.'); | 184 expect(elementAlt.text).toEqual('Igor, Misko and one other person are vi
ewing.'); |
185 | 185 |
186 _.rootScope.context['viewCount'] = 4; | 186 _.rootScope.context['viewCount'] = 4; |
187 _.rootScope.apply(); | 187 _.rootScope.apply(); |
188 expect(element.text).toEqual('Igor, Misko and 2 other people are viewing
.'); | 188 expect(element.text).toEqual('Igor, Misko and 2 other people are viewing
.'); |
189 expect(elementAlt.text).toEqual('Igor, Misko and 2 other people are view
ing.'); | 189 expect(elementAlt.text).toEqual('Igor, Misko and 2 other people are view
ing.'); |
190 }))); | 190 })); |
191 }); | 191 }); |
192 }); | 192 }); |
193 } | 193 } |
OLD | NEW |