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

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

Issue 180843004: Revert revision 33053 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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
1 library input_select_spec; 1 library input_select_spec;
2 2
3 import '../_specs.dart'; 3 import '../_specs.dart';
4 4
5 //TODO(misko): re-enabled disabled tests once we have forms. 5 //TODO(misko): re-enabled disabled tests once we have forms.
6 6
7 main() { 7 main() {
8 describe('input-select', () { 8 describe('input-select', () {
9 9
10 describe('ng-value', () { 10 describe('ng-value', () {
11 TestBed _; 11 TestBed _;
12 beforeEach(inject((TestBed tb) => _ = tb)); 12 beforeEach(inject((TestBed tb) => _ = tb));
13 13
14 it('should retrieve using ng-value', () { 14 it('should retrieve using ng-value', () {
15 _.compile( 15 _.compile(
16 '<select ng-model="robot" probe="p">' 16 '<select ng-model="robot" probe="p">'
17 '<option ng-repeat="r in robots" ng-value="r">{{r.name}}</option>' 17 '<option ng-repeat="r in robots" ng-value="r">{{r.name}}</option>'
18 '</select>'); 18 '</select>');
19 var r2d2 = {"name":"r2d2"}; 19 var r2d2 = { "name":"r2d2"};
20 var c3p0 = {"name":"c3p0"}; 20 var c3p0 = {"name":"c3p0"};
21 _.rootScope.context['robots'] = [ r2d2, c3p0 ]; 21 _.rootScope.robots = [ r2d2, c3p0 ];
22 _.rootScope.apply(); 22 _.rootScope.$digest();
23 _.selectOption(_.rootElement, 'c3p0'); 23 _.selectOption(_.rootElement, 'c3p0');
24 expect(_.rootScope.context['robot']).toEqual(c3p0); 24 expect(_.rootScope.robot).toEqual(c3p0);
25 25
26 _.rootScope.context['robot'] = r2d2; 26 _.rootScope.robot = r2d2;
27 _.rootScope.apply(); 27 _.rootScope.$digest();
28 expect(_.rootScope.context['robot']).toEqual(r2d2); 28 expect(_.rootScope.robot).toEqual(r2d2);
29 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']); 29 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']);
30 }); 30 });
31 31
32 it('should retrieve using ng-value', () { 32 it('should retrieve using ng-value', () {
33 _.compile( 33 _.compile(
34 '<select ng-model="robot" probe="p" multiple>' 34 '<select ng-model="robot" probe="p" multiple>'
35 '<option ng-repeat="r in robots" ng-value="r">{{r.name}}</option>' 35 '<option ng-repeat="r in robots" ng-value="r">{{r.name}}</option>'
36 '</select>'); 36 '</select>');
37 var r2d2 = { "name":"r2d2"}; 37 var r2d2 = { "name":"r2d2"};
38 var c3p0 = {"name":"c3p0"}; 38 var c3p0 = {"name":"c3p0"};
39 _.rootScope.context['robots'] = [ r2d2, c3p0 ]; 39 _.rootScope.robots = [ r2d2, c3p0 ];
40 _.rootScope.apply(); 40 _.rootScope.$digest();
41 _.selectOption(_.rootElement, 'c3p0'); 41 _.selectOption(_.rootElement, 'c3p0');
42 expect(_.rootScope.context['robot']).toEqual([c3p0]); 42 expect(_.rootScope.robot).toEqual([c3p0]);
43 43
44 _.rootScope.context['robot'] = [r2d2]; 44 _.rootScope.robot = [r2d2];
45 _.rootScope.apply(); 45 _.rootScope.$digest();
46 expect(_.rootScope.context['robot']).toEqual([r2d2]); 46 expect(_.rootScope.robot).toEqual([r2d2]);
47 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']); 47 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']);
48 }); 48 });
49 }); 49 });
50 50
51 TestBed _; 51 TestBed _;
52 52
53 beforeEach(inject((TestBed tb) => _ = tb)); 53 beforeEach(inject((TestBed tb) => _ = tb));
54 54
55 describe('select-one', () { 55 describe('select-one', () {
56 it('should compile children of a select without a ngModel, but not create a model for it', 56 it('should compile children of a select without a ngModel, but not create a model for it',
57 () { 57 () {
58 _.compile( 58 _.compile(
59 '<select>' 59 '<select>'
60 '<option selected="true">{{a}}</option>' 60 '<option selected="true">{{a}}</option>'
61 '<option value="">{{b}}</option>' 61 '<option value="">{{b}}</option>'
62 '<option>C</option>' 62 '<option>C</option>'
63 '</select>'); 63 '</select>');
64 _.rootScope.apply(() { 64 _.rootScope.$apply(() {
65 _.rootScope.context['a'] = 'foo'; 65 _.rootScope['a'] = 'foo';
66 _.rootScope.context['b'] = 'bar'; 66 _.rootScope['b'] = 'bar';
67 }); 67 });
68 68
69 expect(_.rootElement.text).toEqual('foobarC'); 69 expect(_.rootElement.text).toEqual('foobarC');
70 }); 70 });
71 71
72 it('should not interfere with selection via selected attr if ngModel direc tive is not present', 72 it('should not interfere with selection via selected attr if ngModel direc tive is not present',
73 () { 73 () {
74 _.compile( 74 _.compile(
75 '<select>' 75 '<select>'
76 '<option>not me</option>' 76 '<option>not me</option>'
77 '<option selected>me!</option>' 77 '<option selected>me!</option>'
78 '<option>nah</option>' 78 '<option>nah</option>'
79 '</select>'); 79 '</select>');
80 _.rootScope.apply(); 80 _.rootScope.$digest();
81 81
82 expect(_.rootElement).toEqualSelect(['not me', ['me!'], 'nah']); 82 expect(_.rootElement).toEqualSelect(['not me', ['me!'], 'nah']);
83 }); 83 });
84 84
85 it('should work with repeated value options', () { 85 it('should work with repeated value options', () {
86 _.compile( 86 _.compile(
87 '<select ng-model="robot" probe="p">' 87 '<select ng-model="robot" probe="p">'
88 '<option ng-repeat="r in robots">{{r}}</option>' 88 '<option ng-repeat="r in robots">{{r}}</option>'
89 '</select>'); 89 '</select>');
90 90
91 _.rootScope.context['robots'] = ['c3p0', 'r2d2']; 91 _.rootScope['robots'] = ['c3p0', 'r2d2'];
92 _.rootScope.context['robot'] = 'r2d2'; 92 _.rootScope['robot'] = 'r2d2';
93 _.rootScope.apply(); 93 _.rootScope.$apply();
94 94
95 var select = _.rootScope.context['p'].directive(InputSelectDirective); 95 var select = _.rootScope['p'].directive(InputSelectDirective);
96 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]); 96 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]);
97 97
98 _.rootElement.querySelectorAll('option')[0].selected = true; 98 _.rootElement.querySelectorAll('option')[0].selected = true;
99 _.triggerEvent(_.rootElement, 'change'); 99 _.triggerEvent(_.rootElement, 'change');
100 100
101 101
102 expect(_.rootElement).toEqualSelect([['c3p0'], 'r2d2']); 102 expect(_.rootElement).toEqualSelect([['c3p0'], 'r2d2']);
103 expect(_.rootScope.context['robot']).toEqual('c3p0'); 103 expect(_.rootScope['robot']).toEqual('c3p0');
104 104
105 _.rootScope.apply(() { 105 _.rootScope.$apply(() {
106 _.rootScope.context['robots'].insert(0, 'wallee'); 106 _.rootScope['robots'].insert(0, 'wallee');
107 }); 107 });
108 expect(_.rootElement).toEqualSelect(['wallee', ['c3p0'], 'r2d2']); 108 expect(_.rootElement).toEqualSelect(['wallee', ['c3p0'], 'r2d2']);
109 expect(_.rootScope.context['robot']).toEqual('c3p0'); 109 expect(_.rootScope['robot']).toEqual('c3p0');
110 110
111 _.rootScope.apply(() { 111 _.rootScope.$apply(() {
112 _.rootScope.context['robots'] = ['c3p0+', 'r2d2+']; 112 _.rootScope['robots'] = ['c3p0+', 'r2d2+'];
113 _.rootScope.context['robot'] = 'r2d2+'; 113 _.rootScope['robot'] = 'r2d2+';
114 }); 114 });
115 115
116 expect(_.rootElement).toEqualSelect(['c3p0+', ['r2d2+']]); 116 expect(_.rootElement).toEqualSelect(['c3p0+', ['r2d2+']]);
117 expect(_.rootScope.context['robot']).toEqual('r2d2+'); 117 expect(_.rootScope['robot']).toEqual('r2d2+');
118 }); 118 });
119 119
120 describe('empty option', () { 120 describe('empty option', () {
121 it('should select the empty option when model is undefined', () { 121 it('should select the empty option when model is undefined', () {
122 _.compile( 122 _.compile(
123 '<select ng-model="robot">' + 123 '<select ng-model="robot">' +
124 '<option value="">--select--</option>' + 124 '<option value="">--select--</option>' +
125 '<option value="x">robot x</option>' + 125 '<option value="x">robot x</option>' +
126 '<option value="y">robot y</option>' + 126 '<option value="y">robot y</option>' +
127 '</select>'); 127 '</select>');
128 _.rootScope.apply(); 128 _.rootScope.$digest();
129 129
130 expect(_.rootElement).toEqualSelect([[''], 'x', 'y']); 130 expect(_.rootElement).toEqualSelect([[''], 'x', 'y']);
131 }); 131 });
132 132
133 it('should support defining an empty option anywhere in the option list' , () { 133 it('should support defining an empty option anywhere in the option list' , () {
134 _.compile( 134 _.compile(
135 '<select ng-model="robot">' + 135 '<select ng-model="robot">' +
136 '<option value="x">robot x</option>' + 136 '<option value="x">robot x</option>' +
137 '<option value="">--select--</option>' + 137 '<option value="">--select--</option>' +
138 '<option value="y">robot y</option>' + 138 '<option value="y">robot y</option>' +
139 '</select>'); 139 '</select>');
140 _.rootScope.apply(); 140 _.rootScope.$digest();
141 141
142 expect(_.rootElement).toEqualSelect(['x', [''], 'y']); 142 expect(_.rootElement).toEqualSelect(['x', [''], 'y']);
143 }); 143 });
144 144
145 it('should set the model to empty string when empty option is selected', () { 145 it('should set the model to empty string when empty option is selected', () {
146 _.rootScope.context['robot'] = 'x'; 146 _.rootScope['robot'] = 'x';
147 _.compile( 147 _.compile(
148 '<select ng-model="robot" probe="p">' + 148 '<select ng-model="robot" probe="p">' +
149 '<option value="">--select--</option>' + 149 '<option value="">--select--</option>' +
150 '<option value="x">robot x</option>' + 150 '<option value="x">robot x</option>' +
151 '<option value="y">robot y</option>' + 151 '<option value="y">robot y</option>' +
152 '</select>'); 152 '</select>');
153 _.rootScope.apply(); 153 _.rootScope.$digest();
154 154
155 var select = _.rootScope.context['p'].directive(InputSelectDirective); 155 var select = _.rootScope['p'].directive(InputSelectDirective);
156 156
157 expect(_.rootElement).toEqualSelect(['', ['x'], 'y']); 157 expect(_.rootElement).toEqualSelect(['', ['x'], 'y']);
158 158
159 _.selectOption(_.rootElement, '--select--'); 159 _.selectOption(_.rootElement, '--select--');
160 160
161 expect(_.rootElement).toEqualSelect([[''], 'x', 'y']); 161 expect(_.rootElement).toEqualSelect([[''], 'x', 'y']);
162 expect(_.rootScope.context['robot']).toEqual(null); 162 expect(_.rootScope['robot']).toEqual(null);
163 }); 163 });
164 164
165 describe('interactions with repeated options', () { 165 describe('interactions with repeated options', () {
166 it('should select empty option when model is undefined', () { 166 it('should select empty option when model is undefined', () {
167 _.rootScope.context['robots'] = ['c3p0', 'r2d2']; 167 _.rootScope['robots'] = ['c3p0', 'r2d2'];
168 _.compile( 168 _.compile(
169 '<select ng-model="robot">' + 169 '<select ng-model="robot">' +
170 '<option value="">--select--</option>' + 170 '<option value="">--select--</option>' +
171 '<option ng-repeat="r in robots">{{r}}</option>' + 171 '<option ng-repeat="r in robots">{{r}}</option>' +
172 '</select>'); 172 '</select>');
173 _.rootScope.apply(); 173 _.rootScope.$digest();
174 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']); 174 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']);
175 }); 175 });
176 176
177 it('should set model to empty string when selected', () { 177 it('should set model to empty string when selected', () {
178 _.rootScope.context['robots'] = ['c3p0', 'r2d2']; 178 _.rootScope['robots'] = ['c3p0', 'r2d2'];
179 _.compile( 179 _.compile(
180 '<select ng-model="robot" probe="p">' + 180 '<select ng-model="robot" probe="p">' +
181 '<option value="">--select--</option>' + 181 '<option value="">--select--</option>' +
182 '<option ng-repeat="r in robots">{{r}}</option>' + 182 '<option ng-repeat="r in robots">{{r}}</option>' +
183 '</select>'); 183 '</select>');
184 _.rootScope.apply(); 184 _.rootScope.$digest();
185 var select = _.rootScope.context['p'].directive(InputSelectDirective ); 185 var select = _.rootScope['p'].directive(InputSelectDirective);
186 186
187 _.selectOption(_.rootElement, 'c3p0'); 187 _.selectOption(_.rootElement, 'c3p0');
188 expect(_.rootElement).toEqualSelect(['', ['c3p0'], 'r2d2']); 188 expect(_.rootElement).toEqualSelect(['', ['c3p0'], 'r2d2']);
189 expect( _.rootScope.context['robot']).toEqual('c3p0'); 189 expect( _.rootScope['robot']).toEqual('c3p0');
190 190
191 _.selectOption(_.rootElement, '--select--'); 191 _.selectOption(_.rootElement, '--select--');
192 192
193 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']); 193 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']);
194 expect( _.rootScope.context['robot']).toEqual(null); 194 expect( _.rootScope['robot']).toEqual(null);
195 }); 195 });
196 196
197 it('should not break if both the select and repeater models change at once', () { 197 it('should not break if both the select and repeater models change at once', () {
198 _.compile( 198 _.compile(
199 '<select ng-model="robot">' + 199 '<select ng-model="robot">' +
200 '<option value="">--select--</option>' + 200 '<option value="">--select--</option>' +
201 '<option ng-repeat="r in robots">{{r}}</option>' + 201 '<option ng-repeat="r in robots">{{r}}</option>' +
202 '</select>'); 202 '</select>');
203 _.rootScope.apply(() { 203 _.rootScope.$apply(() {
204 _.rootScope.context['robots'] = ['c3p0', 'r2d2']; 204 _.rootScope['robots'] = ['c3p0', 'r2d2'];
205 _.rootScope.context['robot'] = 'c3p0'; 205 _.rootScope['robot'] = 'c3p0';
206 }); 206 });
207 207
208 expect(_.rootElement).toEqualSelect(['', ['c3p0'], 'r2d2']); 208 expect(_.rootElement).toEqualSelect(['', ['c3p0'], 'r2d2']);
209 209
210 _.rootScope.apply(() { 210 _.rootScope.$apply(() {
211 _.rootScope.context['robots'] = ['wallee']; 211 _.rootScope['robots'] = ['wallee'];
212 _.rootScope.context['robot'] = ''; 212 _.rootScope['robot'] = '';
213 }); 213 });
214 214
215 expect(_.rootElement).toEqualSelect([[''], 'wallee']); 215 expect(_.rootElement).toEqualSelect([[''], 'wallee']);
216 }); 216 });
217 }); 217 });
218 218
219 describe('unknown option', () { 219 describe('unknown option', () {
220 220
221 it("should insert&select temporary unknown option when no options-mode l match", () { 221 it("should insert&select temporary unknown option when no options-mode l match", () {
222 _.compile( 222 _.compile(
223 '<select ng-model="robot">' + 223 '<select ng-model="robot">' +
224 '<option>c3p0</option>' + 224 '<option>c3p0</option>' +
225 '<option>r2d2</option>' + 225 '<option>r2d2</option>' +
226 '</select>'); 226 '</select>');
227 _.rootScope.apply(); 227 _.rootScope.$digest();
228 expect(_.rootElement).toEqualSelect([['?'], 'c3p0', 'r2d2']); 228 expect(_.rootElement).toEqualSelect([['?'], 'c3p0', 'r2d2']);
229 229
230 _.rootScope.apply(() { 230 _.rootScope.$apply(() {
231 _.rootScope.context['robot'] = 'r2d2'; 231 _.rootScope['robot'] = 'r2d2';
232 }); 232 });
233 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]); 233 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]);
234 234
235 235
236 _.rootScope.apply(() { 236 _.rootScope.$apply(() {
237 _.rootScope.context['robot'] = "wallee"; 237 _.rootScope['robot'] = "wallee";
238 }); 238 });
239 expect(_.rootElement).toEqualSelect([['?'], 'c3p0', 'r2d2']); 239 expect(_.rootElement).toEqualSelect([['?'], 'c3p0', 'r2d2']);
240 }); 240 });
241 241
242 it("should NOT insert temporary unknown option when model is undefined and empty " + 242 it("should NOT insert temporary unknown option when model is undefined and empty " +
243 "options is present", () { 243 "options is present", () {
244 _.compile( 244 _.compile(
245 '<select ng-model="robot">' + 245 '<select ng-model="robot">' +
246 '<option value="">--select--</option>' + 246 '<option value="">--select--</option>' +
247 '<option>c3p0</option>' + 247 '<option>c3p0</option>' +
248 '<option>r2d2</option>' + 248 '<option>r2d2</option>' +
249 '</select>'); 249 '</select>');
250 _.rootScope.apply(); 250 _.rootScope.$digest();
251 251
252 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']); 252 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']);
253 expect(_.rootScope.context['robot']).toEqual(null); 253 expect(_.rootScope['robot']).toEqual(null);
254 254
255 _.rootScope.apply(() { 255 _.rootScope.$apply(() {
256 _.rootScope.context['robot'] = 'wallee'; 256 _.rootScope['robot'] = 'wallee';
257 }); 257 });
258 expect(_.rootElement).toEqualSelect([['?'], '', 'c3p0', 'r2d2']); 258 expect(_.rootElement).toEqualSelect([['?'], '', 'c3p0', 'r2d2']);
259 259
260 _.rootScope.apply(() { 260 _.rootScope.$apply(() {
261 _.rootScope.context['robot'] = 'r2d2'; 261 _.rootScope['robot'] = 'r2d2';
262 }); 262 });
263 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]); 263 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]);
264 264
265 _.rootScope.apply(() { 265 _.rootScope.$apply(() {
266 _.rootScope.context['robot'] = null; 266 _.rootScope['robot'] = null;
267 }); 267 });
268 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']); 268 expect(_.rootElement).toEqualSelect([[''], 'c3p0', 'r2d2']);
269 }); 269 });
270 270
271 it("should insert&select temporary unknown option when no options-mode l match, empty " + 271 it("should insert&select temporary unknown option when no options-mode l match, empty " +
272 "option is present and model is defined", () { 272 "option is present and model is defined", () {
273 _.rootScope.context['robot'] = 'wallee'; 273 _.rootScope['robot'] = 'wallee';
274 _.compile( 274 _.compile(
275 '<select ng-model="robot">' + 275 '<select ng-model="robot">' +
276 '<option value="">--select--</option>' + 276 '<option value="">--select--</option>' +
277 '<option>c3p0</option>' + 277 '<option>c3p0</option>' +
278 '<option>r2d2</option>' + 278 '<option>r2d2</option>' +
279 '</select>'); 279 '</select>');
280 _.rootScope.apply(); 280 _.rootScope.$digest();
281 281
282 expect(_.rootElement).toEqualSelect([['?'], '', 'c3p0', 'r2d2']); 282 expect(_.rootElement).toEqualSelect([['?'], '', 'c3p0', 'r2d2']);
283 283
284 _.rootScope.apply(() { 284 _.rootScope.$apply(() {
285 _.rootScope.context['robot'] = 'r2d2'; 285 _.rootScope['robot'] = 'r2d2';
286 }); 286 });
287 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]); 287 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]);
288 }); 288 });
289 289
290 describe('interactions with repeated options', () { 290 describe('interactions with repeated options', () {
291 it('should work with repeated options', () { 291 it('should work with repeated options', () {
292 _.rootScope.context['robots'] = []; 292 _.rootScope['robots'] = [];
293 _.compile( 293 _.compile(
294 '<select ng-model="robot">' + 294 '<select ng-model="robot">' +
295 '<option ng-repeat="r in robots">{{r}}</option>' + 295 '<option ng-repeat="r in robots">{{r}}</option>' +
296 '</select>'); 296 '</select>');
297 _.rootScope.apply(() { 297 _.rootScope.$apply(() {
298 _.rootScope.context['robots'] = []; 298 _.rootScope['robots'] = [];
299 }); 299 });
300 300
301 expect(_.rootElement).toEqualSelect([['?']]); 301 expect(_.rootElement).toEqualSelect([['?']]);
302 expect(_.rootScope.context['robot']).toEqual(null); 302 expect(_.rootScope['robot']).toEqual(null);
303 303
304 _.rootScope.apply(() { 304 _.rootScope.$apply(() {
305 _.rootScope.context['robot'] = 'r2d2'; 305 _.rootScope['robot'] = 'r2d2';
306 }); 306 });
307 expect(_.rootElement).toEqualSelect([['?']]); 307 expect(_.rootElement).toEqualSelect([['?']]);
308 expect(_.rootScope.context['robot']).toEqual('r2d2'); 308 expect(_.rootScope['robot']).toEqual('r2d2');
309 309
310 _.rootScope.apply(() { 310 _.rootScope.$apply(() {
311 _.rootScope.context['robots'] = ['c3p0', 'r2d2']; 311 _.rootScope['robots'] = ['c3p0', 'r2d2'];
312 }); 312 });
313 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]); 313 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]);
314 expect(_.rootScope.context['robot']).toEqual('r2d2'); 314 expect(_.rootScope['robot']).toEqual('r2d2');
315 }); 315 });
316 316
317 it('should work with empty option and repeated options', () { 317 it('should work with empty option and repeated options', () {
318 _.compile( 318 _.compile(
319 '<select ng-model="robot">' + 319 '<select ng-model="robot">' +
320 '<option value="">--select--</option>' + 320 '<option value="">--select--</option>' +
321 '<option ng-repeat="r in robots">{{r}}</option>' + 321 '<option ng-repeat="r in robots">{{r}}</option>' +
322 '</select>'); 322 '</select>');
323 _.rootScope.apply(() { 323 _.rootScope.$apply(() {
324 _.rootScope.context['robots'] = []; 324 _.rootScope['robots'] = [];
325 }); 325 });
326 326
327 expect(_.rootElement).toEqualSelect([['']]); 327 expect(_.rootElement).toEqualSelect([['']]);
328 expect(_.rootScope.context['robot']).toEqual(null); 328 expect(_.rootScope['robot']).toEqual(null);
329 329
330 _.rootScope.apply(() { 330 _.rootScope.$apply(() {
331 _.rootScope.context['robot'] = 'r2d2'; 331 _.rootScope['robot'] = 'r2d2';
332 }); 332 });
333 expect(_.rootElement).toEqualSelect([['?'], '']); 333 expect(_.rootElement).toEqualSelect([['?'], '']);
334 expect(_.rootScope.context['robot']).toEqual('r2d2'); 334 expect(_.rootScope['robot']).toEqual('r2d2');
335 335
336 _.rootScope.apply(() { 336 _.rootScope.$apply(() {
337 _.rootScope.context['robots'] = ['c3p0', 'r2d2']; 337 _.rootScope['robots'] = ['c3p0', 'r2d2'];
338 }); 338 });
339 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]); 339 expect(_.rootElement).toEqualSelect(['', 'c3p0', ['r2d2']]);
340 expect(_.rootScope.context['robot']).toEqual('r2d2'); 340 expect(_.rootScope['robot']).toEqual('r2d2');
341 }); 341 });
342 342
343 it('should insert unknown element when repeater shrinks and selected option is ' + 343 it('should insert unknown element when repeater shrinks and selected option is ' +
344 'unavailable', () { 344 'unavailable', () {
345 345
346 _.compile( 346 _.compile(
347 '<select ng-model="robot">' + 347 '<select ng-model="robot">' +
348 '<option ng-repeat="r in robots">{{r}}</option>' + 348 '<option ng-repeat="r in robots">{{r}}</option>' +
349 '</select>'); 349 '</select>');
350 _.rootScope.apply(() { 350 _.rootScope.$apply(() {
351 _.rootScope.context['robots'] = ['c3p0', 'r2d2']; 351 _.rootScope['robots'] = ['c3p0', 'r2d2'];
352 _.rootScope.context['robot'] = 'r2d2'; 352 _.rootScope['robot'] = 'r2d2';
353 }); 353 });
354 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]); 354 expect(_.rootElement).toEqualSelect(['c3p0', ['r2d2']]);
355 expect(_.rootScope.context['robot']).toEqual('r2d2'); 355 expect(_.rootScope['robot']).toEqual('r2d2');
356 356
357 _.rootScope.apply(() { 357 _.rootScope.$apply(() {
358 _.rootScope.context['robots'].remove('r2d2'); 358 _.rootScope['robots'].remove('r2d2');
359 }); 359 });
360 expect(_.rootScope.context['robot']).toEqual('r2d2'); 360 expect(_.rootScope['robot']).toEqual('r2d2');
361 expect(_.rootElement).toEqualSelect([['?'], 'c3p0']); 361 expect(_.rootElement).toEqualSelect([['?'], 'c3p0']);
362 362
363 _.rootScope.apply(() { 363 _.rootScope.$apply(() {
364 _.rootScope.context['robots'].insert(0, 'r2d2'); 364 _.rootScope['robots'].insert(0, 'r2d2');
365 }); 365 });
366 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']); 366 expect(_.rootElement).toEqualSelect([['r2d2'], 'c3p0']);
367 expect(_.rootScope.context['robot']).toEqual('r2d2'); 367 expect(_.rootScope['robot']).toEqual('r2d2');
368 368
369 _.rootScope.apply(() { 369 _.rootScope.$apply(() {
370 _.rootScope.context['robots'].clear(); 370 _.rootScope['robots'].clear();
371 }); 371 });
372 372
373 expect(_.rootElement).toEqualSelect([['?']]); 373 expect(_.rootElement).toEqualSelect([['?']]);
374 expect(_.rootScope.context['robot']).toEqual('r2d2'); 374 expect(_.rootScope['robot']).toEqual('r2d2');
375 }); 375 });
376 }); 376 });
377 }); 377 });
378 }); 378 });
379 379
380 it('issue #392', () { 380 it('issue #392', () {
381 _.compile( 381 _.compile(
382 '<div>' + 382 '<div>' +
383 '<div ng-if="attached">' + 383 '<div ng-if="attached">' +
384 '<select ng-model="model">' + 384 '<select ng-model="model">' +
385 '<option value="a">foo</option>' + 385 '<option value="a">foo</option>' +
386 '<option value="b">bar</option>' + 386 '<option value="b">bar</option>' +
387 '</select>' + 387 '</select>' +
388 '</div>' + 388 '</div>' +
389 '</div>'); 389 '</div>');
390 _.rootScope.context['model'] = 'b'; 390 _.rootScope.model = 'a';
391 _.rootScope.context['attached'] = true; 391 _.rootScope.attached = true;
392 _.rootScope.apply(); 392 _.rootScope.$apply();
393 expect(_.rootElement).toEqualSelect(['a', ['b']]); 393 expect(_.rootElement).toEqualSelect([['a'], 'b']);
394 _.rootScope.context['attached'] = false; 394 _.rootScope.attached = false;
395 _.rootScope.apply(); 395 _.rootScope.$apply();
396 expect(_.rootElement).toEqualSelect([]); 396 expect(_.rootElement).toEqualSelect([]);
397 _.rootScope.context['attached'] = true; 397 _.rootScope.attached = true;
398 _.rootScope.apply(); 398 _.rootScope.$apply();
399 expect(_.rootElement).toEqualSelect(['a', ['b']]); 399 expect(_.rootElement).toEqualSelect([['a'], 'b']);
400 });
401
402
403 it('issue #428', () {
404 _.compile(
405 '<div>' +
406 '<div ng-if="attached">' +
407 '<select ng-model="model" multiple>' +
408 '<option value="a">foo</option>' +
409 '<option value="b">bar</option>' +
410 '</select>' +
411 '</div>' +
412 '</div>');
413 _.rootScope.context['model'] = ['b'];
414 _.rootScope.context['attached'] = true;
415 _.rootScope.apply();
416 expect(_.rootElement).toEqualSelect(['a', ['b']]);
417 _.rootScope.context['attached'] = false;
418 _.rootScope.apply();
419 expect(_.rootElement).toEqualSelect([]);
420 _.rootScope.context['attached'] = true;
421 _.rootScope.apply();
422 expect(_.rootElement).toEqualSelect(['a', ['b']]);
423 }); 400 });
424 }); 401 });
425 402
426 403
427 describe('select from angular.js', () { 404 describe('select from angular.js', () {
428 TestBed _; 405 TestBed _;
429 beforeEach(inject((TestBed tb) => _ = tb)); 406 beforeEach(inject((TestBed tb) => _ = tb));
430 407
431 var scope, formElement, element; 408 var scope, formElement, element;
432 409
433 compile(html) { 410 compile(html) {
434 _.compile('<form name="form">' + html + '</form>'); 411 _.compile('<form name="form">' + html + '</form>');
435 element = _.rootElement.querySelector('select'); 412 element = _.rootElement.querySelector('select');
436 scope.apply(); 413 scope.$apply();
437 } 414 }
438 415
439 beforeEach(inject((Scope rootScope) { 416 beforeEach(inject((Scope rootScope) {
440 scope = rootScope; 417 scope = rootScope;
441 formElement = element = null; 418 formElement = element = null;
442 })); 419 }));
443 420
444 421
445 afterEach(() { 422 afterEach(() {
446 scope.destroy(); //disables unknown option work during destruction 423 scope.$destroy(); //disables unknown option work during destruction
447 }); 424 });
448 425
449 426
450 describe('select-one', () { 427 describe('select-one', () {
451 428
452 it('should compile children of a select without a ngModel, but not creat e a model for it', 429 it('should compile children of a select without a ngModel, but not creat e a model for it',
453 () { 430 () {
454 compile('<select>' + 431 compile('<select>' +
455 '<option selected="true">{{a}}</option>' + 432 '<option selected="true">{{a}}</option>' +
456 '<option value="">{{b}}</option>' + 433 '<option value="">{{b}}</option>' +
457 '<option>C</option>' + 434 '<option>C</option>' +
458 '</select>'); 435 '</select>');
459 scope.apply(() { 436 scope.$apply(() {
460 scope.context['a'] = 'foo'; 437 scope.a = 'foo';
461 scope.context['b'] = 'bar'; 438 scope.b = 'bar';
462 }); 439 });
463 440
464 expect(element.text).toEqual('foobarC'); 441 expect(element.text).toEqual('foobarC');
465 }); 442 });
466 443
467 444
468 it('should not interfere with selection via selected attr if ngModel dir ective is not present', 445 it('should not interfere with selection via selected attr if ngModel dir ective is not present',
469 () { 446 () {
470 compile('<select>' + 447 compile('<select>' +
471 '<option>not me</option>' + 448 '<option>not me</option>' +
472 '<option selected>me!</option>' + 449 '<option selected>me!</option>' +
473 '<option>nah</option>' + 450 '<option>nah</option>' +
474 '</select>'); 451 '</select>');
475 expect(element).toEqualSelect(['not me', ['me!'], 'nah']); 452 expect(element).toEqualSelect(['not me', ['me!'], 'nah']);
476 }); 453 });
477 454
478 it('should fire ng-change event.', () {
479 var log = '';
480 compile(
481 '<select name="select" ng-model="selection" ng-change="change()">' +
482 '<option value=""></option>' +
483 '<option value="c">C</option>' +
484 '</select>');
485
486 scope.context['change'] = () {
487 log += 'change:${scope.context['selection']};';
488 };
489
490 scope.apply(() {
491 scope.context['selection'] = 'c';
492 });
493
494 element.value = 'c';
495 _.triggerEvent(element, 'change');
496 expect(log).toEqual('change:c;');
497 });
498
499 455
500 xit('should require', () { 456 xit('should require', () {
501 compile( 457 compile(
502 '<select name="select" ng-model="selection" required ng-change="chan ge()">' + 458 '<select name="select" ng-model="selection" required ng-change="chan ge()">' +
503 '<option value=""></option>' + 459 '<option value=""></option>' +
504 '<option value="c">C</option>' + 460 '<option value="c">C</option>' +
505 '</select>'); 461 '</select>');
506 462
507 scope.context['change'] = () { 463 scope.change = () {
508 scope.log += 'change;'; 464 scope.log += 'change;';
509 }; 465 };
510 466
511 scope.apply(() { 467 scope.$apply(() {
512 scope.context['log'] = ''; 468 scope.log = '';
513 scope.context['selection'] = 'c'; 469 scope.selection = 'c';
514 }); 470 });
515 471
516 expect(scope.context['form'].select.$error.required).toEqual(false);; 472 expect(scope.form.select.$error.required).toEqual(false);;
517 expect(element).toEqualValid(); 473 expect(element).toEqualValid();
518 expect(element).toEqualPristine(); 474 expect(element).toEqualPristine();
519 475
520 scope.apply(() { 476 scope.$apply(() {
521 scope.context['selection'] = ''; 477 scope.selection = '';
522 }); 478 });
523 479
524 expect(scope.context['form'].select.$error.required).toEqual(true);; 480 expect(scope.form.select.$error.required).toEqual(true);;
525 expect(element).toEqualInvalid(); 481 expect(element).toEqualInvalid();
526 expect(element).toEqualPristine(); 482 expect(element).toEqualPristine();
527 expect(scope.context['log']).toEqual(''); 483 expect(scope.log).toEqual('');
528 484
529 element[0].value = 'c'; 485 element[0].value = 'c';
530 _.triggerEvent(element, 'change'); 486 _.triggerEvent(element, 'change');
531 expect(element).toEqualValid(); 487 expect(element).toEqualValid();
532 expect(element).toEqualDirty(); 488 expect(element).toEqualDirty();
533 expect(scope.context['log']).toEqual('change;'); 489 expect(scope.log).toEqual('change;');
534 }); 490 });
535 491
536 492
537 xit('should not be invalid if no require', () { 493 xit('should not be invalid if no require', () {
538 compile( 494 compile(
539 '<select name="select" ng-model="selection">' + 495 '<select name="select" ng-model="selection">' +
540 '<option value=""></option>' + 496 '<option value=""></option>' +
541 '<option value="c">C</option>' + 497 '<option value="c">C</option>' +
542 '</select>'); 498 '</select>');
543 499
(...skipping 30 matching lines...) Expand all
574 530
575 describe('select-multiple', () { 531 describe('select-multiple', () {
576 532
577 it('should support type="select-multiple"', () { 533 it('should support type="select-multiple"', () {
578 compile( 534 compile(
579 '<select ng-model="selection" multiple>' + 535 '<select ng-model="selection" multiple>' +
580 '<option>A</option>' + 536 '<option>A</option>' +
581 '<option>B</option>' + 537 '<option>B</option>' +
582 '</select>'); 538 '</select>');
583 539
584 scope.apply(() { 540 scope.$apply(() {
585 scope.context['selection'] = ['A']; 541 scope.selection = ['A'];
586 }); 542 });
587 543
588 expect(element).toEqualSelect([['A'], 'B']); 544 expect(element).toEqualSelect([['A'], 'B']);
589 545
590 scope.apply(() { 546 scope.$apply(() {
591 scope.context['selection'].add('B'); 547 scope.selection.add('B');
592 }); 548 });
593 549
594 expect(element).toEqualSelect([['A'], ['B']]); 550 expect(element).toEqualSelect([['A'], ['B']]);
595 }); 551 });
596 552
597 it('should work with optgroups', () { 553 it('should work with optgroups', () {
598 compile('<select ng-model="selection" multiple>' + 554 compile('<select ng-model="selection" multiple>' +
599 '<optgroup label="group1">' + 555 '<optgroup label="group1">' +
600 '<option>A</option>' + 556 '<option>A</option>' +
601 '<option>B</option>' + 557 '<option>B</option>' +
602 '</optgroup>' + 558 '</optgroup>' +
603 '</select>'); 559 '</select>');
604 560
605 expect(element).toEqualSelect(['A', 'B']); 561 expect(element).toEqualSelect(['A', 'B']);
606 expect(scope.context['selection']).toEqual(null); 562 expect(scope.selection).toEqual(null);
607 563
608 scope.apply(() { 564 scope.$apply(() {
609 scope.context['selection'] = ['A']; 565 scope.selection = ['A'];
610 }); 566 });
611 expect(element).toEqualSelect([['A'], 'B']); 567 expect(element).toEqualSelect([['A'], 'B']);
612 568
613 scope.apply(() { 569 scope.$apply(() {
614 scope.context['selection'].add('B'); 570 scope.selection.add('B');
615 }); 571 });
616 expect(element).toEqualSelect([['A'], ['B']]); 572 expect(element).toEqualSelect([['A'], ['B']]);
617 }); 573 });
618 574
619 xit('should require', () { 575 xit('should require', () {
620 compile( 576 compile(
621 '<select name="select" ng-model="selection" multiple required>' + 577 '<select name="select" ng-model="selection" multiple required>' +
622 '<option>A</option>' + 578 '<option>A</option>' +
623 '<option>B</option>' + 579 '<option>B</option>' +
624 '</select>'); 580 '</select>');
625 581
626 scope.apply(() { 582 scope.$apply(() {
627 scope.context['selection'] = []; 583 scope.selection = [];
628 }); 584 });
629 585
630 expect(scope.context['form'].select.$error.required).toEqual(true);; 586 expect(scope.form.select.$error.required).toEqual(true);;
631 expect(element).toEqualInvalid(); 587 expect(element).toEqualInvalid();
632 expect(element).toEqualPristine(); 588 expect(element).toEqualPristine();
633 589
634 scope.apply(() { 590 scope.$apply(() {
635 scope.context['selection'] = ['A']; 591 scope.selection = ['A'];
636 }); 592 });
637 593
638 expect(element).toEqualValid(); 594 expect(element).toEqualValid();
639 expect(element).toEqualPristine(); 595 expect(element).toEqualPristine();
640 596
641 element[0].value = 'B'; 597 element[0].value = 'B';
642 _.triggerEvent(element, 'change'); 598 _.triggerEvent(element, 'change');
643 expect(element).toEqualValid(); 599 expect(element).toEqualValid();
644 expect(element).toEqualDirty(); 600 expect(element).toEqualDirty();
645 }); 601 });
(...skipping 29 matching lines...) Expand all
675 createSelect({ 631 createSelect({
676 'ng-model':'selected', 632 'ng-model':'selected',
677 'multiple':true 633 'multiple':true
678 }, blank, unknown, 'value in values', 'value.name', 'value'); 634 }, blank, unknown, 'value in values', 'value.name', 'value');
679 } 635 }
680 636
681 637
682 it('should render a list', () { 638 it('should render a list', () {
683 createSingleSelect(); 639 createSingleSelect();
684 640
685 scope.apply(() { 641 scope.$apply(() {
686 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}, {'name': 'C '}]; 642 scope.values = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}];
687 scope.context['selected'] = scope.context['values'][0]; 643 scope.selected = scope.values[0];
688 }); 644 });
689 645
690 var options = element.querySelectorAll('option'); 646 var options = element.querySelectorAll('option');
691 expect(options.length).toEqual(3); 647 expect(options.length).toEqual(3);
692 expect(element).toEqualSelect([['A'], 'B', 'C']); 648 expect(element).toEqualSelect([['A'], 'B', 'C']);
693 }); 649 });
694 650
695 it('should render zero as a valid display value', () { 651 it('should render zero as a valid display value', () {
696 createSingleSelect(); 652 createSingleSelect();
697 653
698 scope.apply(() { 654 scope.$apply(() {
699 scope.context['values'] = [{'name': '0'}, {'name': '1'}, {'name': '2 '}]; 655 scope.values = [{'name': '0'}, {'name': '1'}, {'name': '2'}];
700 scope.context['selected'] = scope.context['values'][0]; 656 scope.selected = scope.values[0];
701 }); 657 });
702 658
703 var options = element.querySelectorAll('option'); 659 var options = element.querySelectorAll('option');
704 expect(options.length).toEqual(3); 660 expect(options.length).toEqual(3);
705 expect(element).toEqualSelect([['0'], '1', '2']); 661 expect(element).toEqualSelect([['0'], '1', '2']);
706 }); 662 });
707 663
708 it('should grow list', () { 664 it('should grow list', () {
709 createSingleSelect(); 665 createSingleSelect();
710 666
711 scope.apply(() { 667 scope.$apply(() {
712 scope.context['values'] = []; 668 scope.values = [];
713 }); 669 });
714 670
715 expect(element.querySelectorAll('option').length).toEqual(1); // becau se we add special empty option 671 expect(element.querySelectorAll('option').length).toEqual(1); // becau se we add special empty option
716 expect(element.querySelectorAll('option')[0].text).toEqual(''); 672 expect(element.querySelectorAll('option')[0].text).toEqual('');
717 expect(element.querySelectorAll('option')[0].value).toEqual('?'); 673 expect(element.querySelectorAll('option')[0].value).toEqual('?');
718 674
719 scope.apply(() { 675 scope.$apply(() {
720 scope.context['values'].add({'name':'A'}); 676 scope.values.add({'name':'A'});
721 scope.context['selected'] = scope.context['values'][0]; 677 scope.selected = scope.values[0];
722 }); 678 });
723 679
724 expect(element.querySelectorAll('option').length).toEqual(1); 680 expect(element.querySelectorAll('option').length).toEqual(1);
725 expect(element).toEqualSelect([['A']]); 681 expect(element).toEqualSelect([['A']]);
726 682
727 scope.apply(() { 683 scope.$apply(() {
728 scope.context['values'].add({'name':'B'}); 684 scope.values.add({'name':'B'});
729 }); 685 });
730 686
731 expect(element.querySelectorAll('option').length).toEqual(2); 687 expect(element.querySelectorAll('option').length).toEqual(2);
732 expect(element).toEqualSelect([['A'], 'B']); 688 expect(element).toEqualSelect([['A'], 'B']);
733 }); 689 });
734 690
735 691
736 it('should shrink list', () { 692 it('should shrink list', () {
737 createSingleSelect(); 693 createSingleSelect();
738 694
739 scope.apply(() { 695 scope.$apply(() {
740 scope.context['values'] = [{'name':'A'}, {'name':'B'}, {'name':'C'}] ; 696 scope.values = [{'name':'A'}, {'name':'B'}, {'name':'C'}];
741 scope.context['selected'] = scope.context['values'][0]; 697 scope.selected = scope.values[0];
742 }); 698 });
743 699
744 expect(element.querySelectorAll('option').length).toEqual(3); 700 expect(element.querySelectorAll('option').length).toEqual(3);
745 701
746 scope.apply(() { 702 scope.$apply(() {
747 scope.context['values'].removeLast(); 703 scope.values.removeLast();
748 }); 704 });
749 705
750 expect(element.querySelectorAll('option').length).toEqual(2); 706 expect(element.querySelectorAll('option').length).toEqual(2);
751 expect(element).toEqualSelect([['A'], 'B']); 707 expect(element).toEqualSelect([['A'], 'B']);
752 708
753 scope.apply(() { 709 scope.$apply(() {
754 scope.context['values'].removeLast(); 710 scope.values.removeLast();
755 }); 711 });
756 712
757 expect(element.querySelectorAll('option').length).toEqual(1); 713 expect(element.querySelectorAll('option').length).toEqual(1);
758 expect(element).toEqualSelect([['A']]); 714 expect(element).toEqualSelect([['A']]);
759 715
760 scope.apply(() { 716 scope.$apply(() {
761 scope.context['values'].removeLast(); 717 scope.values.removeLast();
762 scope.context['selected'] = null; 718 scope.selected = null;
763 }); 719 });
764 720
765 expect(element.querySelectorAll('option').length).toEqual(1); // we ad d back the special empty option 721 expect(element.querySelectorAll('option').length).toEqual(1); // we ad d back the special empty option
766 }); 722 });
767 723
768 724
769 it('should shrink and then grow list', () { 725 it('should shrink and then grow list', () {
770 createSingleSelect(); 726 createSingleSelect();
771 727
772 scope.apply(() { 728 scope.$apply(() {
773 scope.context['values'] = [{'name':'A'}, {'name':'B'}, {'name':'C'}] ; 729 scope.values = [{'name':'A'}, {'name':'B'}, {'name':'C'}];
774 scope.context['selected'] = scope.context['values'][0]; 730 scope.selected = scope.values[0];
775 }); 731 });
776 732
777 expect(element.querySelectorAll('option').length).toEqual(3); 733 expect(element.querySelectorAll('option').length).toEqual(3);
778 734
779 scope.apply(() { 735 scope.$apply(() {
780 scope.context['values'] = [{'name': '1'}, {'name': '2'}]; 736 scope.values = [{'name': '1'}, {'name': '2'}];
781 scope.context['selected'] = scope.context['values'][0]; 737 scope.selected = scope.values[0];
782 }); 738 });
783 739
784 expect(element.querySelectorAll('option').length).toEqual(2); 740 expect(element.querySelectorAll('option').length).toEqual(2);
785 741
786 scope.apply(() { 742 scope.$apply(() {
787 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}, {'name': 'C '}]; 743 scope.values = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}];
788 scope.context['selected'] = scope.context['values'][0]; 744 scope.selected = scope.values[0];
789 }); 745 });
790 746
791 expect(element.querySelectorAll('option').length).toEqual(3); 747 expect(element.querySelectorAll('option').length).toEqual(3);
792 }); 748 });
793 749
794 750
795 it('should update list', () { 751 it('should update list', () {
796 createSingleSelect(); 752 createSingleSelect();
797 753
798 scope.apply(() { 754 scope.$apply(() {
799 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}, {'name': 'C '}]; 755 scope.values = [{'name': 'A'}, {'name': 'B'}, {'name': 'C'}];
800 scope.context['selected'] = scope.context['values'][0]; 756 scope.selected = scope.values[0];
801 }); 757 });
802 expect(element).toEqualSelect([['A'], 'B', 'C']); 758 expect(element).toEqualSelect([['A'], 'B', 'C']);
803 scope.apply(() { 759 scope.$apply(() {
804 scope.context['values'] = [{'name': 'B'}, {'name': 'C'}, {'name': 'D '}]; 760 scope.values = [{'name': 'B'}, {'name': 'C'}, {'name': 'D'}];
805 scope.context['selected'] = scope.context['values'][0]; 761 scope.selected = scope.values[0];
806 }); 762 });
807 763
808 var options = element.querySelectorAll('option'); 764 var options = element.querySelectorAll('option');
809 expect(options.length).toEqual(3); 765 expect(options.length).toEqual(3);
810 expect(element).toEqualSelect([['B'], 'C', 'D']); 766 expect(element).toEqualSelect([['B'], 'C', 'D']);
811 }); 767 });
812 768
813 769
814 it('should preserve existing options', () { 770 it('should preserve existing options', () {
815 createSingleSelect(true); 771 createSingleSelect(true);
816 772
817 scope.apply(() { 773 scope.$apply(() {
818 scope.context['values'] = []; 774 scope.values = [];
819 }); 775 });
820 776
821 expect(element.querySelectorAll('option').length).toEqual(1); 777 expect(element.querySelectorAll('option').length).toEqual(1);
822 778
823 scope.apply(() { 779 scope.$apply(() {
824 scope.context['values'] = [{'name': 'A'}]; 780 scope.values = [{'name': 'A'}];
825 scope.context['selected'] = scope.context['values'][0]; 781 scope.selected = scope.values[0];
826 }); 782 });
827 783
828 expect(element.querySelectorAll('option').length).toEqual(2); 784 expect(element.querySelectorAll('option').length).toEqual(2);
829 expect(element.querySelectorAll('option')[0].text).toEqual('blank'); 785 expect(element.querySelectorAll('option')[0].text).toEqual('blank');
830 expect(element.querySelectorAll('option')[1].text).toEqual('A'); 786 expect(element.querySelectorAll('option')[1].text).toEqual('A');
831 787
832 scope.apply(() { 788 scope.$apply(() {
833 scope.context['values'] = []; 789 scope.values = [];
834 scope.context['selected'] = null; 790 scope.selected = null;
835 }); 791 });
836 792
837 expect(element.querySelectorAll('option').length).toEqual(1); 793 expect(element.querySelectorAll('option').length).toEqual(1);
838 expect(element.querySelectorAll('option')[0].text).toEqual('blank'); 794 expect(element.querySelectorAll('option')[0].text).toEqual('blank');
839 }); 795 });
840 796
841 describe('binding', () { 797 describe('binding', () {
842 798
843 it('should bind to scope value', () { 799 it('should bind to scope value', () {
844 createSingleSelect(); 800 createSingleSelect();
845 801
846 scope.apply(() { 802 scope.$apply(() {
847 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}]; 803 scope.values = [{'name': 'A'}, {'name': 'B'}];
848 scope.context['selected'] = scope.context['values'][0]; 804 scope.selected = scope.values[0];
849 }); 805 });
850 806
851 expect(element).toEqualSelect([['A'], 'B']); 807 expect(element).toEqualSelect([['A'], 'B']);
852 808
853 scope.apply(() { 809 scope.$apply(() {
854 scope.context['selected'] = scope.context['values'][1]; 810 scope.selected = scope.values[1];
855 }); 811 });
856 812
857 expect(element).toEqualSelect(['A', ['B']]); 813 expect(element).toEqualSelect(['A', ['B']]);
858 }); 814 });
859 815
860 816
861 // TODO(misko): re-enable once we support group by 817 // TODO(misko): re-enable once we support group by
862 xit('should bind to scope value and group', () { 818 xit('should bind to scope value and group', () {
863 createSelect({ 819 createSelect({
864 'ng-model': 'selected', 820 'ng-model': 'selected',
865 'ng-options': 'item.name group by item.group for item in values' 821 'ng-options': 'item.name group by item.group for item in values'
866 }); 822 });
867 823
868 scope.apply(() { 824 scope.$apply(() {
869 scope.context['values'] = [{'name': 'A'}, 825 scope.values = [{'name': 'A'},
870 {'name': 'B', group: 'first'}, 826 {'name': 'B', group: 'first'},
871 {'name': 'C', group: 'second'}, 827 {'name': 'C', group: 'second'},
872 {'name': 'D', group: 'first'}, 828 {'name': 'D', group: 'first'},
873 {'name': 'E', group: 'second'}]; 829 {'name': 'E', group: 'second'}];
874 scope.context['selected'] = scope.context['values'][3]; 830 scope.selected = scope.values[3];
875 }); 831 });
876 832
877 expect(element).toEqualSelect(['A', 'B', ['D'], 'C', 'E']); 833 expect(element).toEqualSelect(['A', 'B', ['D'], 'C', 'E']);
878 834
879 var first = element.querySelectorAll('optgroup')[0]; 835 var first = element.querySelectorAll('optgroup')[0];
880 var b = first.querySelectorAll('option')[0]; 836 var b = first.querySelectorAll('option')[0];
881 var d = first.querySelectorAll('option')[1]; 837 var d = first.querySelectorAll('option')[1];
882 expect(first.attr('label')).toEqual('first'); 838 expect(first.attr('label')).toEqual('first');
883 expect(b.text).toEqual('B'); 839 expect(b.text).toEqual('B');
884 expect(d.text).toEqual('D'); 840 expect(d.text).toEqual('D');
885 841
886 var second = element.querySelectorAll('optgroup')[1]; 842 var second = element.querySelectorAll('optgroup')[1];
887 var c = second.querySelectorAll('option')[0]; 843 var c = second.querySelectorAll('option')[0];
888 var e = second.querySelectorAll('option')[1]; 844 var e = second.querySelectorAll('option')[1];
889 expect(second.attr('label')).toEqual('second'); 845 expect(second.attr('label')).toEqual('second');
890 expect(c.text).toEqual('C'); 846 expect(c.text).toEqual('C');
891 expect(e.text).toEqual('E'); 847 expect(e.text).toEqual('E');
892 848
893 scope.apply(() { 849 scope.$apply(() {
894 scope.context['selected'] = scope.context['values'][0]; 850 scope.selected = scope.values[0];
895 }); 851 });
896 852
897 expect(element.value).toEqual('0'); 853 expect(element.value).toEqual('0');
898 }); 854 });
899 855
900 856
901 it('should bind to scope value through experession', () { 857 it('should bind to scope value through experession', () {
902 createSelect({'ng-model': 'selected'}, null, null, 'item in values', 'item.name', 'item.id'); 858 createSelect({'ng-model': 'selected'}, null, null, 'item in values', 'item.name', 'item.id');
903 859
904 scope.apply(() { 860 scope.$apply(() {
905 scope.context['values'] = [{'id': 10, 'name': 'A'}, {'id': 20, 'na me': 'B'}]; 861 scope.values = [{'id': 10, 'name': 'A'}, {'id': 20, 'name': 'B'}];
906 scope.context['selected'] = scope.context['values'][0]['id']; 862 scope.selected = scope.values[0]['id'];
907 }); 863 });
908 864
909 expect(element).toEqualSelect([['A'], 'B']); 865 expect(element).toEqualSelect([['A'], 'B']);
910 866
911 scope.apply(() { 867 scope.$apply(() {
912 scope.context['selected'] = scope.context['values'][1]['id']; 868 scope.selected = scope.values[1]['id'];
913 }); 869 });
914 870
915 expect(element).toEqualSelect(['A', ['B']]); 871 expect(element).toEqualSelect(['A', ['B']]);
916 }); 872 });
917 873
918 874
919 it('should insert a blank option if bound to null', () { 875 it('should insert a blank option if bound to null', () {
920 createSingleSelect(); 876 createSingleSelect();
921 877
922 scope.apply(() { 878 scope.$apply(() {
923 scope.context['values'] = [{'name': 'A'}]; 879 scope.values = [{'name': 'A'}];
924 scope.context['selected'] = null; 880 scope.selected = null;
925 }); 881 });
926 882
927 expect(element.querySelectorAll('option').length).toEqual(2); 883 expect(element.querySelectorAll('option').length).toEqual(2);
928 expect(element).toEqualSelect([['?'], 'A']); 884 expect(element).toEqualSelect([['?'], 'A']);
929 expect(element.querySelectorAll('option')[0].value).toEqual('?'); 885 expect(element.querySelectorAll('option')[0].value).toEqual('?');
930 886
931 scope.apply(() { 887 scope.$apply(() {
932 scope.context['selected'] = scope.context['values'][0]; 888 scope.selected = scope.values[0];
933 }); 889 });
934 890
935 expect(element).toEqualSelect([['A']]); 891 expect(element).toEqualSelect([['A']]);
936 expect(element.querySelectorAll('option').length).toEqual(1); 892 expect(element.querySelectorAll('option').length).toEqual(1);
937 }); 893 });
938 894
939 895
940 it('should reuse blank option if bound to null', () { 896 it('should reuse blank option if bound to null', () {
941 createSingleSelect(true); 897 createSingleSelect(true);
942 898
943 scope.apply(() { 899 scope.$apply(() {
944 scope.context['values'] = [{'name': 'A'}]; 900 scope.values = [{'name': 'A'}];
945 scope.context['selected'] = null; 901 scope.selected = null;
946 }); 902 });
947 903
948 expect(element.querySelectorAll('option').length).toEqual(2); 904 expect(element.querySelectorAll('option').length).toEqual(2);
949 expect(element.value).toEqual(''); 905 expect(element.value).toEqual('');
950 expect(element.querySelectorAll('option')[0].value).toEqual(''); 906 expect(element.querySelectorAll('option')[0].value).toEqual('');
951 907
952 scope.apply(() { 908 scope.$apply(() {
953 scope.context['selected'] = scope.context['values'][0]; 909 scope.selected = scope.values[0];
954 }); 910 });
955 911
956 expect(element).toEqualSelect(['', ['A']]); 912 expect(element).toEqualSelect(['', ['A']]);
957 expect(element.querySelectorAll('option').length).toEqual(2); 913 expect(element.querySelectorAll('option').length).toEqual(2);
958 }); 914 });
959 915
960 916
961 it('should insert a unknown option if bound to something not in the li st', () { 917 it('should insert a unknown option if bound to something not in the li st', () {
962 createSingleSelect(); 918 createSingleSelect();
963 919
964 scope.apply(() { 920 scope.$apply(() {
965 scope.context['values'] = [{'name': 'A'}]; 921 scope.values = [{'name': 'A'}];
966 scope.context['selected'] = {}; 922 scope.selected = {};
967 }); 923 });
968 924
969 expect(element.querySelectorAll('option').length).toEqual(2); 925 expect(element.querySelectorAll('option').length).toEqual(2);
970 expect(element.value).toEqual('?'); 926 expect(element.value).toEqual('?');
971 expect(element.querySelectorAll('option')[0].value).toEqual('?'); 927 expect(element.querySelectorAll('option')[0].value).toEqual('?');
972 928
973 scope.apply(() { 929 scope.$apply(() {
974 scope.context['selected'] = scope.context['values'][0]; 930 scope.selected = scope.values[0];
975 }); 931 });
976 932
977 expect(element).toEqualSelect([['A']]); 933 expect(element).toEqualSelect([['A']]);
978 expect(element.querySelectorAll('option').length).toEqual(1); 934 expect(element.querySelectorAll('option').length).toEqual(1);
979 }); 935 });
980 936
981 937
982 it('should select correct input if previously selected option was "?"' , () { 938 it('should select correct input if previously selected option was "?"' , () {
983 createSingleSelect(); 939 createSingleSelect();
984 940
985 scope.apply(() { 941 scope.$apply(() {
986 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}]; 942 scope.values = [{'name': 'A'}, {'name': 'B'}];
987 scope.context['selected'] = {}; 943 scope.selected = {};
988 }); 944 });
989 945
990 expect(element.querySelectorAll('option').length).toEqual(3); 946 expect(element.querySelectorAll('option').length).toEqual(3);
991 expect(element.value).toEqual('?'); 947 expect(element.value).toEqual('?');
992 expect(element.querySelectorAll('option')[0].value).toEqual('?'); 948 expect(element.querySelectorAll('option')[0].value).toEqual('?');
993 949
994 _.selectOption(element, 'A'); 950 _.selectOption(element, 'A');
995 expect(scope.context['selected']).toBe(scope.context['values'][0]); 951 expect(scope.selected).toBe(scope.values[0]);
996 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ; 952 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;
997 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;; 953 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;;
998 expect(element.querySelectorAll('option').length).toEqual(2); 954 expect(element.querySelectorAll('option').length).toEqual(2);
999 }); 955 });
1000 }); 956 });
1001 957
1002 958
1003 describe('blank option', () { 959 describe('blank option', () {
1004 960
1005 it('should be compiled as template, be watched and updated', () { 961 it('should be compiled as template, be watched and updated', () {
1006 var option; 962 var option;
1007 createSingleSelect('<option value="">blank is {{blankVal}}</option>' ); 963 createSingleSelect('<option value="">blank is {{blankVal}}</option>' );
1008 964
1009 scope.apply(() { 965 scope.$apply(() {
1010 scope.context['blankVal'] = 'so blank'; 966 scope.blankVal = 'so blank';
1011 scope.context['values'] = [{'name': 'A'}]; 967 scope.values = [{'name': 'A'}];
1012 }); 968 });
1013 969
1014 // check blank option is first and is compiled 970 // check blank option is first and is compiled
1015 expect(element.querySelectorAll('option').length).toEqual(2); 971 expect(element.querySelectorAll('option').length).toEqual(2);
1016 option = element.querySelectorAll('option')[0]; 972 option = element.querySelectorAll('option')[0];
1017 expect(option.value).toEqual(''); 973 expect(option.value).toEqual('');
1018 expect(option.text).toEqual('blank is so blank'); 974 expect(option.text).toEqual('blank is so blank');
1019 975
1020 scope.apply(() { 976 scope.$apply(() {
1021 scope.context['blankVal'] = 'not so blank'; 977 scope.blankVal = 'not so blank';
1022 }); 978 });
1023 979
1024 // check blank option is first and is compiled 980 // check blank option is first and is compiled
1025 expect(element.querySelectorAll('option').length).toEqual(2); 981 expect(element.querySelectorAll('option').length).toEqual(2);
1026 option = element.querySelectorAll('option')[0]; 982 option = element.querySelectorAll('option')[0];
1027 expect(option.value).toEqual(''); 983 expect(option.value).toEqual('');
1028 expect(option.text).toEqual('blank is not so blank'); 984 expect(option.text).toEqual('blank is not so blank');
1029 }); 985 });
1030 986
1031 987
1032 it('should support binding via ngBindTemplate directive', () { 988 it('should support binding via ngBindTemplate directive', () {
1033 var option; 989 var option;
1034 createSingleSelect('<option value="" ng-bind="\'blank is \' + blankV al"></option>'); 990 createSingleSelect('<option value="" ng-bind="\'blank is \' + blankV al"></option>');
1035 991
1036 scope.apply(() { 992 scope.$apply(() {
1037 scope.context['blankVal'] = 'so blank'; 993 scope.blankVal = 'so blank';
1038 scope.context['values'] = [{'name': 'A'}]; 994 scope.values = [{'name': 'A'}];
1039 }); 995 });
1040 996
1041 // check blank option is first and is compiled 997 // check blank option is first and is compiled
1042 expect(element.querySelectorAll('option').length).toEqual(2); 998 expect(element.querySelectorAll('option').length).toEqual(2);
1043 option = element.querySelectorAll('option')[0]; 999 option = element.querySelectorAll('option')[0];
1044 expect(option.value).toEqual(''); 1000 expect(option.value).toEqual('');
1045 expect(option.text).toEqual('blank is so blank'); 1001 expect(option.text).toEqual('blank is so blank');
1046 }); 1002 });
1047 1003
1048 1004
1049 it('should support biding via ngBind attribute', () { 1005 it('should support biding via ngBind attribute', () {
1050 var option; 1006 var option;
1051 createSingleSelect('<option value="" ng-bind="blankVal"></option>'); 1007 createSingleSelect('<option value="" ng-bind="blankVal"></option>');
1052 1008
1053 scope.apply(() { 1009 scope.$apply(() {
1054 scope.context['blankVal'] = 'is blank'; 1010 scope.blankVal = 'is blank';
1055 scope.context['values'] = [{'name': 'A'}]; 1011 scope.values = [{'name': 'A'}];
1056 }); 1012 });
1057 1013
1058 // check blank option is first and is compiled 1014 // check blank option is first and is compiled
1059 expect(element.querySelectorAll('option').length).toEqual(2); 1015 expect(element.querySelectorAll('option').length).toEqual(2);
1060 option = element.querySelectorAll('option')[0]; 1016 option = element.querySelectorAll('option')[0];
1061 expect(option.value).toEqual(''); 1017 expect(option.value).toEqual('');
1062 expect(option.text).toEqual('is blank'); 1018 expect(option.text).toEqual('is blank');
1063 }); 1019 });
1064 1020
1065 1021
1066 it('should be rendered with the attributes preserved', () { 1022 it('should be rendered with the attributes preserved', () {
1067 var option; 1023 var option;
1068 createSingleSelect('<option value="" class="coyote" id="road-runner" ' + 1024 createSingleSelect('<option value="" class="coyote" id="road-runner" ' +
1069 'custom-attr="custom-attr">{{blankVal}}</option>'); 1025 'custom-attr="custom-attr">{{blankVal}}</option>');
1070 1026
1071 scope.apply(() { 1027 scope.$apply(() {
1072 scope.context['blankVal'] = 'is blank'; 1028 scope.blankVal = 'is blank';
1073 }); 1029 });
1074 1030
1075 // check blank option is first and is compiled 1031 // check blank option is first and is compiled
1076 option = element.querySelectorAll('option')[0]; 1032 option = element.querySelectorAll('option')[0];
1077 expect(option.classes.contains('coyote')).toEqual(true);; 1033 expect(option.classes.contains('coyote')).toEqual(true);;
1078 expect(option.attributes['id']).toEqual('road-runner'); 1034 expect(option.attributes['id']).toEqual('road-runner');
1079 expect(option.attributes['custom-attr']).toEqual('custom-attr'); 1035 expect(option.attributes['custom-attr']).toEqual('custom-attr');
1080 }); 1036 });
1081 1037
1082 it('should be selected, if it is available and no other option is sele cted', () { 1038 it('should be selected, if it is available and no other option is sele cted', () {
1083 // selectedIndex is used here because $ incorrectly reports element. value 1039 // selectedIndex is used here because $ incorrectly reports element. value
1084 scope.apply(() { 1040 scope.$apply(() {
1085 scope.context['values'] = [{'name': 'A'}]; 1041 scope.values = [{'name': 'A'}];
1086 }); 1042 });
1087 createSingleSelect(true); 1043 createSingleSelect(true);
1088 // ensure the first option (the blank option) is selected 1044 // ensure the first option (the blank option) is selected
1089 expect(element.selectedIndex).toEqual(0); 1045 expect(element.selectedIndex).toEqual(0);
1090 scope.apply(); 1046 scope.$digest();
1091 // ensure the option has not changed following the digest 1047 // ensure the option has not changed following the digest
1092 expect(element.selectedIndex).toEqual(0); 1048 expect(element.selectedIndex).toEqual(0);
1093 }); 1049 });
1094 }); 1050 });
1095 1051
1096 1052
1097 describe('on change', () { 1053 describe('on change', () {
1098 1054
1099 it('should update model on change', () { 1055 it('should update model on change', () {
1100 createSingleSelect(); 1056 createSingleSelect();
1101 1057
1102 scope.apply(() { 1058 scope.$apply(() {
1103 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}]; 1059 scope.values = [{'name': 'A'}, {'name': 'B'}];
1104 scope.context['selected'] = scope.context['values'][0]; 1060 scope.selected = scope.values[0];
1105 }); 1061 });
1106 1062
1107 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ; 1063 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;
1108 1064
1109 element.querySelectorAll('option')[1].selected = true; 1065 element.querySelectorAll('option')[1].selected = true;
1110 _.triggerEvent(element, 'change'); 1066 _.triggerEvent(element, 'change');
1111 expect(scope.context['selected']).toEqual(scope.context['values'][1] ); 1067 expect(scope.selected).toEqual(scope.values[1]);
1112 }); 1068 });
1113 1069
1114 1070
1115 it('should update model on change through expression', () { 1071 it('should update model on change through expression', () {
1116 createSelect({'ng-model': 'selected'}, null, null, 1072 createSelect({'ng-model': 'selected'}, null, null,
1117 'item in values', 'item.name', 'item.id'); 1073 'item in values', 'item.name', 'item.id');
1118 1074
1119 scope.apply(() { 1075 scope.$apply(() {
1120 scope.context['values'] = [{'id': 10, 'name': 'A'}, {'id': 20, 'na me': 'B'}]; 1076 scope.values = [{'id': 10, 'name': 'A'}, {'id': 20, 'name': 'B'}];
1121 scope.context['selected'] = scope.context['values'][0]['id']; 1077 scope.selected = scope.values[0]['id'];
1122 }); 1078 });
1123 1079
1124 expect(element).toEqualSelect([['A'], 'B']); 1080 expect(element).toEqualSelect([['A'], 'B']);
1125 1081
1126 element.querySelectorAll('option')[1].selected = true; 1082 element.querySelectorAll('option')[1].selected = true;
1127 _.triggerEvent(element, 'change'); 1083 _.triggerEvent(element, 'change');
1128 expect(scope.context['selected']).toEqual(scope.context['values'][1] ['id']); 1084 expect(scope.selected).toEqual(scope.values[1]['id']);
1129 }); 1085 });
1130 1086
1131 1087
1132 it('should update model to null on change', () { 1088 it('should update model to null on change', () {
1133 createSingleSelect(true); 1089 createSingleSelect(true);
1134 1090
1135 scope.apply(() { 1091 scope.$apply(() {
1136 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}]; 1092 scope.values = [{'name': 'A'}, {'name': 'B'}];
1137 scope.context['selected'] = scope.context['values'][0]; 1093 scope.selected = scope.values[0];
1138 element.value = '0'; 1094 element.value = '0';
1139 }); 1095 });
1140 1096
1141 _.selectOption(element, 'blank'); 1097 _.selectOption(element, 'blank');
1142 expect(element).toEqualSelect([[''], 'A', 'B']); 1098 expect(element).toEqualSelect([[''], 'A', 'B']);
1143 1099
1144 expect(scope.context['selected']).toEqual(null); 1100 expect(scope.selected).toEqual(null);
1145 }); 1101 });
1146 }); 1102 });
1147 1103
1148 1104
1149 describe('select-many', () { 1105 describe('select-many', () {
1150 1106
1151 it('should read multiple selection', () { 1107 it('should read multiple selection', () {
1152 createMultiSelect(); 1108 createMultiSelect();
1153 1109
1154 scope.apply(() { 1110 scope.$apply(() {
1155 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}]; 1111 scope.values = [{'name': 'A'}, {'name': 'B'}];
1156 scope.context['selected'] = []; 1112 scope.selected = [];
1157 }); 1113 });
1158 1114
1159 expect(element.querySelectorAll('option').length).toEqual(2); 1115 expect(element.querySelectorAll('option').length).toEqual(2);
1160 expect(element.querySelectorAll('option')[0].selected).toEqual(false );; 1116 expect(element.querySelectorAll('option')[0].selected).toEqual(false );;
1161 expect(element.querySelectorAll('option')[1].selected).toEqual(false );; 1117 expect(element.querySelectorAll('option')[1].selected).toEqual(false );;
1162 1118
1163 scope.apply(() { 1119 scope.$apply(() {
1164 scope.context['selected'].add(scope.context['values'][1]); 1120 scope.selected.add(scope.values[1]);
1165 }); 1121 });
1166 1122
1167 expect(element.querySelectorAll('option').length).toEqual(2); 1123 expect(element.querySelectorAll('option').length).toEqual(2);
1168 expect(element.querySelectorAll('option')[0].selected).toEqual(false );; 1124 expect(element.querySelectorAll('option')[0].selected).toEqual(false );;
1169 expect(element.querySelectorAll('option')[1].selected).toEqual(true) ;; 1125 expect(element.querySelectorAll('option')[1].selected).toEqual(true) ;;
1170 1126
1171 scope.apply(() { 1127 scope.$apply(() {
1172 scope.context['selected'].add(scope.context['values'][0]); 1128 scope.selected.add(scope.values[0]);
1173 }); 1129 });
1174 1130
1175 expect(element.querySelectorAll('option').length).toEqual(2); 1131 expect(element.querySelectorAll('option').length).toEqual(2);
1176 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;; 1132 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;;
1177 expect(element.querySelectorAll('option')[1].selected).toEqual(true) ;; 1133 expect(element.querySelectorAll('option')[1].selected).toEqual(true) ;;
1178 }); 1134 });
1179 1135
1180 1136
1181 it('should update model on change', () { 1137 it('should update model on change', () {
1182 createMultiSelect(); 1138 createMultiSelect();
1183 1139
1184 scope.apply(() { 1140 scope.$apply(() {
1185 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}]; 1141 scope.values = [{'name': 'A'}, {'name': 'B'}];
1186 scope.context['selected'] = []; 1142 scope.selected = [];
1187 }); 1143 });
1188 1144
1189 element.querySelectorAll('option')[0].selected = true; 1145 element.querySelectorAll('option')[0].selected = true;
1190 1146
1191 _.triggerEvent(element, 'change'); 1147 _.triggerEvent(element, 'change');
1192 expect(scope.context['selected']).toEqual([scope.context['values'][0 ]]); 1148 expect(scope.selected).toEqual([scope.values[0]]);
1193 }); 1149 });
1194 1150
1195 1151
1196 it('should deselect all options when model is emptied', () { 1152 it('should deselect all options when model is emptied', () {
1197 createMultiSelect(); 1153 createMultiSelect();
1198 scope.apply(() { 1154 scope.$apply(() {
1199 scope.context['values'] = [{'name': 'A'}, {'name': 'B'}]; 1155 scope.values = [{'name': 'A'}, {'name': 'B'}];
1200 scope.context['selected'] = [scope.context['values'][0]]; 1156 scope.selected = [scope.values[0]];
1201 }); 1157 });
1202 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ; 1158 expect(element.querySelectorAll('option')[0].selected).toEqual(true) ;
1203 1159
1204 scope.apply(() { 1160 scope.$apply(() {
1205 scope.context['selected'].removeLast(); 1161 scope.selected.removeLast();
1206 }); 1162 });
1207 1163
1208 expect(element.querySelectorAll('option')[0].selected).toEqual(false ); 1164 expect(element.querySelectorAll('option')[0].selected).toEqual(false );
1209 }); 1165 });
1210 }); 1166 });
1211 1167
1212 1168
1213 xdescribe('ngRequired', () { 1169 xdescribe('ngRequired', () {
1214 1170
1215 it('should allow bindings on ngRequired', () { 1171 it('should allow bindings on ngRequired', () {
1216 createSelect({ 1172 createSelect({
1217 'ng-model': 'value', 1173 'ng-model': 'value',
1218 'ng-options': 'item.name for item in values', 1174 'ng-options': 'item.name for item in values',
1219 'ng-required': 'required' 1175 'ng-required': 'required'
1220 }, true); 1176 }, true);
1221 1177
1222 1178
1223 scope.apply(() { 1179 scope.$apply(() {
1224 scope.context['values'] = [{'name': 'A', 'id': 1}, {'name': 'B', ' id': 2}]; 1180 scope.values = [{'name': 'A', 'id': 1}, {'name': 'B', 'id': 2}];
1225 scope.context['required'] = false; 1181 scope.required = false;
1226 }); 1182 });
1227 1183
1228 element.value = ''; 1184 element.value = '';
1229 _.triggerEvent(element, 'change'); 1185 _.triggerEvent(element, 'change');
1230 expect(element).toEqualValid(); 1186 expect(element).toEqualValid();
1231 1187
1232 scope.apply(() { 1188 scope.$apply(() {
1233 scope.context['required'] = true; 1189 scope.required = true;
1234 }); 1190 });
1235 expect(element).toEqualInvalid(); 1191 expect(element).toEqualInvalid();
1236 1192
1237 scope.apply(() { 1193 scope.$apply(() {
1238 scope.context['value'] = scope.context['values'][0]; 1194 scope.value = scope.values[0];
1239 }); 1195 });
1240 expect(element).toEqualValid(); 1196 expect(element).toEqualValid();
1241 1197
1242 element.value = ''; 1198 element.value = '';
1243 _.triggerEvent(element, 'change'); 1199 _.triggerEvent(element, 'change');
1244 expect(element).toEqualInvalid(); 1200 expect(element).toEqualInvalid();
1245 1201
1246 scope.apply(() { 1202 scope.$apply(() {
1247 scope.context['required'] = false; 1203 scope.required = false;
1248 }); 1204 });
1249 expect(element).toEqualValid(); 1205 expect(element).toEqualValid();
1250 }); 1206 });
1251 }); 1207 });
1252 }); 1208 });
1253 1209
1254 1210
1255 describe('option', () { 1211 describe('option', () {
1256 1212
1257 it('should populate value attribute on OPTION', () { 1213 it('should populate value attribute on OPTION', () {
1258 compile('<select ng-model="x"><option selected>abc</option></select>') ; 1214 compile('<select ng-model="x"><option selected>abc</option></select>') ;
1259 expect(element).toEqualSelect([['?'], 'abc']); 1215 expect(element).toEqualSelect([['?'], 'abc']);
1260 }); 1216 });
1261 1217
1262 it('should ignore value if already exists', () { 1218 it('should ignore value if already exists', () {
1263 compile('<select ng-model="x"><option value="abc">xyz</option></select >'); 1219 compile('<select ng-model="x"><option value="abc">xyz</option></select >');
1264 expect(element).toEqualSelect([['?'], 'abc']); 1220 expect(element).toEqualSelect([['?'], 'abc']);
1265 }); 1221 });
1266 1222
1267 it('should set value even if self closing HTML', () { 1223 it('should set value even if self closing HTML', () {
1268 scope.context['x'] = 'hello'; 1224 scope.x = 'hello';
1269 compile('<select ng-model="x"><option>hello</select>'); 1225 compile('<select ng-model="x"><option>hello</select>');
1270 expect(element).toEqualSelect([['hello']]); 1226 expect(element).toEqualSelect([['hello']]);
1271 }); 1227 });
1272 1228
1273 it('should not blow up when option directive is found inside of a datali st', 1229 it('should not blow up when option directive is found inside of a datali st',
1274 () { 1230 () {
1275 _.compile('<div>' + 1231 _.compile('<div>' +
1276 '<datalist><option>some val</option></datalist>' + 1232 '<datalist><option>some val</option></datalist>' +
1277 '<span>{{foo}}</span>' + 1233 '<span>{{foo}}</span>' +
1278 '</div>'); 1234 '</div>');
1279 1235
1280 _.rootScope.context['foo'] = 'success'; 1236 _.rootScope.foo = 'success';
1281 _.rootScope.apply(); 1237 _.rootScope.$digest();
1282 expect(_.rootElement.querySelector('span').text).toEqual('success'); 1238 expect(_.rootElement.querySelector('span').text).toEqual('success');
1283 }); 1239 });
1284 }); 1240 });
1285 }); 1241 });
1286 }); 1242 });
1287 } 1243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698