Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: third_party/pkg/angular/test/directive/ng_pluralize_spec.dart

Issue 148453003: Updating Angular version (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 library ng_pluralize_spec;
2
3 import '../_specs.dart';
4
5 main() {
6 describe('PluralizeDirective', () {
7
8 describe('deal with pluralized strings without offset', () {
9 var element;
10 var elementAlt;
11 var elt;
12 TestBed _;
13
14 beforeEach(inject((TestBed tb) {
15 _ = tb;
16
17 element = _.compile(
18 '<ng-pluralize count="email"' +
19 "when=\"{'-1': 'You have negative email. Whohoo!'," +
20 "'0': 'You have no new email'," +
21 "'one': 'You have one new email'," +
22 "'other': 'You have {} new emails'}\">" +
23 '</ng-pluralize>'
24 );
25
26 elementAlt = _.compile(
27 '<p ng-pluralize count="email" ' +
28 "when-minus-1='You have negative email. Whohoo!' " +
29 "when-0='You have no new email' " +
30 "when-one='You have one new email' " +
31 "when-other='You have {} new emails'>" +
32 '</p>'
33 );
34 }));
35
36 it('should show single/plural strings', () {
37 _.rootScope.email = '0';
38 _.rootScope.$digest();
39 expect(element.text).toEqual('You have no new email');
40 expect(elementAlt.text).toEqual('You have no new email');
41
42 _.rootScope.email = '0';
43 _.rootScope.$digest();
44 expect(element.text).toEqual('You have no new email');
45 expect(elementAlt.text).toEqual('You have no new email');
46
47 _.rootScope.email = 1;
48 _.rootScope.$digest();
49 expect(element.text).toEqual('You have one new email');
50 expect(elementAlt.text).toEqual('You have one new email');
51
52 _.rootScope.email = 0.01;
53 _.rootScope.$digest();
54 expect(element.text).toEqual('You have 0.01 new emails');
55 expect(elementAlt.text).toEqual('You have 0.01 new emails');
56
57 _.rootScope.email = '0.1';
58 _.rootScope.$digest();
59 expect(element.text).toEqual('You have 0.1 new emails');
60 expect(elementAlt.text).toEqual('You have 0.1 new emails');
61
62 _.rootScope.email = 2;
63 _.rootScope.$digest();
64 expect(element.text).toEqual('You have 2 new emails');
65 expect(elementAlt.text).toEqual('You have 2 new emails');
66
67 _.rootScope.email = -0.1;
68 _.rootScope.$digest();
69 expect(element.text).toEqual('You have -0.1 new emails');
70 expect(elementAlt.text).toEqual('You have -0.1 new emails');
71
72 _.rootScope.email = '-0.01';
73 _.rootScope.$digest();
74 expect(element.text).toEqual('You have -0.01 new emails');
75 expect(elementAlt.text).toEqual('You have -0.01 new emails');
76
77 _.rootScope.email = -2;
78 _.rootScope.$digest();
79 expect(element.text).toEqual('You have -2 new emails');
80 expect(elementAlt.text).toEqual('You have -2 new emails');
81
82 _.rootScope.email = -1;
83 _.rootScope.$digest();
84 expect(element.text).toEqual('You have negative email. Whohoo!');
85 expect(elementAlt.text).toEqual('You have negative email. Whohoo!');
86 });
87
88 it('should show single/plural strings with mal-formed inputs', () {
89 _.rootScope.email = '';
90 _.rootScope.$digest();
91 expect(element.text).toEqual('');
92 expect(elementAlt.text).toEqual('');
93
94 _.rootScope.email = null;
95 _.rootScope.$digest();
96 expect(element.text).toEqual('');
97 expect(elementAlt.text).toEqual('');
98
99 _.rootScope.email = 'a3';
100 _.rootScope.$digest();
101 expect(element.text).toEqual('');
102 expect(elementAlt.text).toEqual('');
103
104 _.rootScope.email = '011';
105 _.rootScope.$digest();
106 expect(element.text).toEqual('You have 11 new emails');
107 expect(elementAlt.text).toEqual('You have 11 new emails');
108
109 _.rootScope.email = '-011';
110 _.rootScope.$digest();
111 expect(element.text).toEqual('You have -11 new emails');
112 expect(elementAlt.text).toEqual('You have -11 new emails');
113
114 _.rootScope.email = '1fff';
115 _.rootScope.$digest();
116 expect(element.text).toEqual('');
117 expect(elementAlt.text).toEqual('');
118
119 _.rootScope.email = '0aa22';
120 _.rootScope.$digest();
121 expect(element.text).toEqual('');
122 expect(elementAlt.text).toEqual('');
123
124 _.rootScope.email = '000001';
125 _.rootScope.$digest();
126 expect(element.text).toEqual('You have one new email');
127 expect(elementAlt.text).toEqual('You have one new email');
128 });
129 });
130
131 describe('edge cases', () {
132 it('should be able to handle empty strings as possible values', (inject((T estBed _) {
133 var element = _.compile(
134 '<ng-pluralize count="email"' +
135 "when=\"{'0': ''," +
136 "'one': 'Some text'," +
137 "'other': 'Some text'}\">" +
138 '</ng-pluralize>');
139 _.rootScope.email = '0';
140 _.rootScope.$digest();
141 expect(element.text).toEqual('');
142 })));
143 });
144
145 describe('deal with pluralized strings with offset', () {
146 it('should show single/plural strings with offset', (inject((TestBed _) {
147 var element = _.compile(
148 "<ng-pluralize count='viewCount' offset='2' " +
149 "when=\"{'0': 'Nobody is viewing.'," +
150 "'1': '{{p1}} is viewing.'," +
151 "'2': '{{p1}} and {{p2}} are viewing.'," +
152 "'one': '{{p1}}, {{p2}} and one other person are viewing.'," +
153 "'other': '{{p1}}, {{p2}} and {} other people are viewing.'}\">" +
154 "</ng-pluralize>");
155 var elementAlt = _.compile(
156 "<ng-pluralize count='viewCount' offset='2' " +
157 "when-0='Nobody is viewing.'" +
158 "when-1='{{p1}} is viewing.'" +
159 "when-2='{{p1}} and {{p2}} are viewing.'" +
160 "when-one='{{p1}}, {{p2}} and one other person are viewing.'" +
161 "when-other='{{p1}}, {{p2}} and {} other people are viewing.'>" +
162 "</ng-pluralize>");
163 _.rootScope.p1 = 'Igor';
164 _.rootScope.p2 = 'Misko';
165
166 _.rootScope.viewCount = 0;
167 _.rootScope.$digest();
168 expect(element.text).toEqual('Nobody is viewing.');
169 expect(elementAlt.text).toEqual('Nobody is viewing.');
170
171 _.rootScope.viewCount = 1;
172 _.rootScope.$digest();
173 expect(element.text).toEqual('Igor is viewing.');
174 expect(elementAlt.text).toEqual('Igor is viewing.');
175
176 _.rootScope.viewCount = 2;
177 _.rootScope.$digest();
178 expect(element.text).toEqual('Igor and Misko are viewing.');
179 expect(elementAlt.text).toEqual('Igor and Misko are viewing.');
180
181 _.rootScope.viewCount = 3;
182 _.rootScope.$digest();
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.');
185
186 _.rootScope.viewCount = 4;
187 _.rootScope.$digest();
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.');
190 })));
191 });
192 });
193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698