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