OLD | NEW |
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((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.context['robots'] = [ r2d2, c3p0 ]; |
22 _.rootScope.apply(); | 22 _.rootScope.apply(); |
(...skipping 17 matching lines...) Expand all Loading... |
40 _.rootScope.apply(); | 40 _.rootScope.apply(); |
41 _.selectOption(_.rootElement, 'c3p0'); | 41 _.selectOption(_.rootElement, 'c3p0'); |
42 expect(_.rootScope.context['robot']).toEqual([c3p0]); | 42 expect(_.rootScope.context['robot']).toEqual([c3p0]); |
43 | 43 |
44 _.rootScope.context['robot'] = [r2d2]; | 44 _.rootScope.context['robot'] = [r2d2]; |
45 _.rootScope.apply(); | 45 _.rootScope.apply(); |
46 expect(_.rootScope.context['robot']).toEqual([r2d2]); | 46 expect(_.rootScope.context['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((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>'); |
(...skipping 21 matching lines...) Expand all Loading... |
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.context['robots'] = ['c3p0', 'r2d2']; |
92 _.rootScope.context['robot'] = 'r2d2'; | 92 _.rootScope.context['robot'] = 'r2d2'; |
93 _.rootScope.apply(); | 93 _.rootScope.apply(); |
94 | 94 |
95 var select = _.rootScope.context['p'].directive(InputSelectDirective); | 95 var select = _.rootScope.context['p'].directive(InputSelect); |
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.context['robot']).toEqual('c3p0'); |
104 | 104 |
105 _.rootScope.apply(() { | 105 _.rootScope.apply(() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.context['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.apply(); |
154 | 154 |
155 var select = _.rootScope.context['p'].directive(InputSelectDirective); | 155 var select = _.rootScope.context['p'].directive(InputSelect); |
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.context['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.context['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.apply(); |
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.context['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.apply(); |
185 var select = _.rootScope.context['p'].directive(InputSelectDirective
); | 185 var select = _.rootScope.context['p'].directive(InputSelect); |
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.context['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.context['robot']).toEqual(null); |
195 }); | 195 }); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 expect(_.rootElement).toEqualSelect([]); | 419 expect(_.rootElement).toEqualSelect([]); |
420 _.rootScope.context['attached'] = true; | 420 _.rootScope.context['attached'] = true; |
421 _.rootScope.apply(); | 421 _.rootScope.apply(); |
422 expect(_.rootElement).toEqualSelect(['a', ['b']]); | 422 expect(_.rootElement).toEqualSelect(['a', ['b']]); |
423 }); | 423 }); |
424 }); | 424 }); |
425 | 425 |
426 | 426 |
427 describe('select from angular.js', () { | 427 describe('select from angular.js', () { |
428 TestBed _; | 428 TestBed _; |
429 beforeEach(inject((TestBed tb) => _ = tb)); | 429 beforeEach((TestBed tb) => _ = tb); |
430 | 430 |
431 var scope, formElement, element; | 431 var scope, formElement, element; |
432 | 432 |
433 compile(html) { | 433 compile(html) { |
434 _.compile('<form name="form">' + html + '</form>'); | 434 _.compile('<form name="form">' + html + '</form>'); |
435 element = _.rootElement.querySelector('select'); | 435 element = _.rootElement.querySelector('select'); |
436 scope.apply(); | 436 scope.apply(); |
437 } | 437 } |
438 | 438 |
439 beforeEach(inject((Scope rootScope) { | 439 beforeEach((Scope rootScope) { |
440 scope = rootScope; | 440 scope = rootScope; |
441 formElement = element = null; | 441 formElement = element = null; |
442 })); | 442 }); |
443 | 443 |
444 | 444 |
445 afterEach(() { | 445 afterEach(() { |
446 scope.destroy(); //disables unknown option work during destruction | 446 scope.destroy(); //disables unknown option work during destruction |
447 }); | 447 }); |
448 | 448 |
449 | 449 |
450 describe('select-one', () { | 450 describe('select-one', () { |
451 | 451 |
452 it('should compile children of a select without a ngModel, but not creat
e a model for it', | 452 it('should compile children of a select without a ngModel, but not creat
e a model for it', |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 scope.apply(() { | 490 scope.apply(() { |
491 scope.context['selection'] = 'c'; | 491 scope.context['selection'] = 'c'; |
492 }); | 492 }); |
493 | 493 |
494 element.value = 'c'; | 494 element.value = 'c'; |
495 _.triggerEvent(element, 'change'); | 495 _.triggerEvent(element, 'change'); |
496 expect(log).toEqual('change:c;'); | 496 expect(log).toEqual('change:c;'); |
497 }); | 497 }); |
498 | 498 |
499 | 499 |
500 xit('should require', () { | 500 it('should require', () { |
501 compile( | 501 compile( |
502 '<select name="select" ng-model="selection" required ng-change="chan
ge()">' + | 502 '<select name="select" ng-model="selection" probe="i" required ng-ch
ange="change()">' + |
503 '<option value=""></option>' + | 503 '<option value=""></option>' + |
504 '<option value="c">C</option>' + | 504 '<option value="c">C</option>' + |
505 '</select>'); | 505 '</select>'); |
506 | 506 |
| 507 var element = scope.context['i'].element; |
| 508 |
| 509 scope.context['log'] = ''; |
507 scope.context['change'] = () { | 510 scope.context['change'] = () { |
508 scope.log += 'change;'; | 511 scope.context['log'] += 'change;'; |
509 }; | 512 }; |
510 | 513 |
511 scope.apply(() { | 514 scope.apply(() { |
512 scope.context['log'] = ''; | 515 scope.context['log'] = ''; |
513 scope.context['selection'] = 'c'; | 516 scope.context['selection'] = 'c'; |
514 }); | 517 }); |
515 | 518 |
516 expect(scope.context['form'].select.$error.required).toEqual(false);; | 519 expect(scope.context['form']['select'].hasErrorState('ng-required')).t
oEqual(false); |
517 expect(element).toEqualValid(); | 520 expect(scope.context['form']['select'].valid).toEqual(true); |
518 expect(element).toEqualPristine(); | 521 expect(scope.context['form']['select'].pristine).toEqual(true); |
519 | 522 |
520 scope.apply(() { | 523 scope.apply(() { |
521 scope.context['selection'] = ''; | 524 scope.context['selection'] = ''; |
522 }); | 525 }); |
523 | 526 |
524 expect(scope.context['form'].select.$error.required).toEqual(true);; | 527 expect(scope.context['form']['select'].hasErrorState('ng-required')).t
oEqual(true); |
525 expect(element).toEqualInvalid(); | 528 expect(scope.context['form']['select'].invalid).toEqual(true); |
526 expect(element).toEqualPristine(); | 529 expect(scope.context['form']['select'].pristine).toEqual(true); |
527 expect(scope.context['log']).toEqual(''); | 530 expect(scope.context['log']).toEqual(''); |
528 | 531 |
529 element[0].value = 'c'; | 532 element.value = 'c'; |
530 _.triggerEvent(element, 'change'); | 533 _.triggerEvent(element, 'change'); |
531 expect(element).toEqualValid(); | 534 scope.apply(); |
532 expect(element).toEqualDirty(); | 535 |
| 536 expect(scope.context['form']['select'].valid).toEqual(true); |
| 537 expect(scope.context['form']['select'].dirty).toEqual(true); |
533 expect(scope.context['log']).toEqual('change;'); | 538 expect(scope.context['log']).toEqual('change;'); |
534 }); | 539 }); |
535 | 540 |
536 | 541 |
537 xit('should not be invalid if no require', () { | 542 it('should not be invalid if no require', () { |
538 compile( | 543 compile( |
539 '<select name="select" ng-model="selection">' + | 544 '<select name="select" ng-model="selection">' + |
540 '<option value=""></option>' + | 545 '<option value=""></option>' + |
541 '<option value="c">C</option>' + | 546 '<option value="c">C</option>' + |
542 '</select>'); | 547 '</select>'); |
543 | 548 |
544 expect(element).toEqualValid(); | 549 expect(scope.context['form']['select'].valid).toEqual(true); |
545 expect(element).toEqualPristine(); | 550 expect(scope.context['form']['select'].pristine).toEqual(true); |
546 }); | 551 }); |
547 | 552 |
548 | 553 |
549 describe('empty option', () { | 554 describe('empty option', () { |
550 | 555 |
551 it('should select the empty option when model is undefined', () { | 556 it('should select the empty option when model is undefined', () { |
552 compile('<select ng-model="robot">' + | 557 compile('<select ng-model="robot">' + |
553 '<option value="">--select--</option>' + | 558 '<option value="">--select--</option>' + |
554 '<option value="x">robot x</option>' + | 559 '<option value="x">robot x</option>' + |
555 '<option value="y">robot y</option>' + | 560 '<option value="y">robot y</option>' + |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 scope.context['selection'] = ['A']; | 614 scope.context['selection'] = ['A']; |
610 }); | 615 }); |
611 expect(element).toEqualSelect([['A'], 'B']); | 616 expect(element).toEqualSelect([['A'], 'B']); |
612 | 617 |
613 scope.apply(() { | 618 scope.apply(() { |
614 scope.context['selection'].add('B'); | 619 scope.context['selection'].add('B'); |
615 }); | 620 }); |
616 expect(element).toEqualSelect([['A'], ['B']]); | 621 expect(element).toEqualSelect([['A'], ['B']]); |
617 }); | 622 }); |
618 | 623 |
619 xit('should require', () { | 624 it('should require', () { |
620 compile( | 625 compile( |
621 '<select name="select" ng-model="selection" multiple required>' + | 626 '<select name="select" probe="i" ng-model="selection" multiple requi
red>' + |
622 '<option>A</option>' + | 627 '<option>A</option>' + |
623 '<option>B</option>' + | 628 '<option>B</option>' + |
624 '</select>'); | 629 '</select>'); |
625 | 630 |
| 631 var element = scope.context['i'].element; |
626 scope.apply(() { | 632 scope.apply(() { |
627 scope.context['selection'] = []; | 633 scope.context['selection'] = []; |
628 }); | 634 }); |
629 | 635 |
630 expect(scope.context['form'].select.$error.required).toEqual(true);; | 636 expect(scope.context['form']['select'].hasErrorState('ng-required')).t
oEqual(true); |
631 expect(element).toEqualInvalid(); | 637 expect(scope.context['form']['select'].invalid).toEqual(true); |
632 expect(element).toEqualPristine(); | 638 expect(scope.context['form']['select'].pristine).toEqual(true); |
633 | 639 |
634 scope.apply(() { | 640 scope.apply(() { |
635 scope.context['selection'] = ['A']; | 641 scope.context['selection'] = ['A']; |
636 }); | 642 }); |
637 | 643 |
638 expect(element).toEqualValid(); | 644 expect(scope.context['form']['select'].valid).toEqual(true); |
639 expect(element).toEqualPristine(); | 645 expect(scope.context['form']['select'].pristine).toEqual(true); |
640 | 646 |
641 element[0].value = 'B'; | 647 element.value = 'B'; |
642 _.triggerEvent(element, 'change'); | 648 _.triggerEvent(element, 'change'); |
643 expect(element).toEqualValid(); | 649 |
644 expect(element).toEqualDirty(); | 650 expect(scope.context['form']['select'].valid).toEqual(true); |
| 651 expect(scope.context['form']['select'].dirty).toEqual(true); |
645 }); | 652 }); |
646 }); | 653 }); |
647 | 654 |
648 | 655 |
649 describe('ngOptions', () { | 656 describe('ngOptions', () { |
650 createSelect(attrs, [blank, unknown, ngRepeat, text, ngValue]) { | 657 createSelect(attrs, [blank, unknown, ngRepeat, text, ngValue]) { |
651 var html = '<select'; | 658 var html = '<select'; |
652 attrs.forEach((key, value) { | 659 attrs.forEach((key, value) { |
653 if (value is bool) { | 660 if (value is bool) { |
654 if (value != null) html += ' $key'; | 661 if (value != null) html += ' $key'; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 expect(element).toEqualSelect([['A'], 'B']); | 858 expect(element).toEqualSelect([['A'], 'B']); |
852 | 859 |
853 scope.apply(() { | 860 scope.apply(() { |
854 scope.context['selected'] = scope.context['values'][1]; | 861 scope.context['selected'] = scope.context['values'][1]; |
855 }); | 862 }); |
856 | 863 |
857 expect(element).toEqualSelect(['A', ['B']]); | 864 expect(element).toEqualSelect(['A', ['B']]); |
858 }); | 865 }); |
859 | 866 |
860 | 867 |
861 // TODO(misko): re-enable once we support group by | 868 it('should bind to scope value and group', () { |
862 xit('should bind to scope value and group', () { | 869 var element = _.compile( |
863 createSelect({ | 870 '<select ng-model="selected" probe="p">' |
864 'ng-model': 'selected', | 871 '<optgroup label=\'{{ group["title"] }}\' ng-repeat="group in
values">' |
865 'ng-options': 'item.name group by item.group for item in values' | 872 '<option value=\'{{ item["val"] }}\' ' |
| 873 'ng-repeat=\'item in group["items"]\'>{{ item["name"
] }}</option>' |
| 874 '</optgroup>' |
| 875 '</select>'); |
| 876 |
| 877 scope.apply(() { |
| 878 scope.context['values'] = [ |
| 879 { 'title': 'first', 'items': |
| 880 [{ 'val':'a', 'name' : 'A' }, { 'val':'c', 'name' : 'C' } ]}, |
| 881 { 'title': 'second', 'items': |
| 882 [{ 'val':'b', 'name' : 'B' }, { 'val':'d', 'name' : 'D' } ]} |
| 883 ]; |
| 884 scope.context['selected'] = scope.context['values'][1]['items'][0]
['val']; |
866 }); | 885 }); |
867 | 886 |
868 scope.apply(() { | 887 expect(element).toEqualSelect(['a', 'c', ['b'], 'd']); |
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 | 888 |
879 var first = element.querySelectorAll('optgroup')[0]; | 889 var first = element.querySelectorAll('optgroup')[0]; |
880 var b = first.querySelectorAll('option')[0]; | 890 var b = first.querySelectorAll('option')[0]; |
881 var d = first.querySelectorAll('option')[1]; | 891 var d = first.querySelectorAll('option')[1]; |
882 expect(first.attr('label')).toEqual('first'); | 892 expect(first.getAttribute('label')).toEqual('first'); |
883 expect(b.text).toEqual('B'); | 893 expect(b.text).toEqual('A'); |
884 expect(d.text).toEqual('D'); | 894 expect(d.text).toEqual('C'); |
885 | 895 |
886 var second = element.querySelectorAll('optgroup')[1]; | 896 var second = element.querySelectorAll('optgroup')[1]; |
887 var c = second.querySelectorAll('option')[0]; | 897 var c = second.querySelectorAll('option')[0]; |
888 var e = second.querySelectorAll('option')[1]; | 898 var e = second.querySelectorAll('option')[1]; |
889 expect(second.attr('label')).toEqual('second'); | 899 expect(second.getAttribute('label')).toEqual('second'); |
890 expect(c.text).toEqual('C'); | 900 expect(c.text).toEqual('B'); |
891 expect(e.text).toEqual('E'); | 901 expect(e.text).toEqual('D'); |
892 | 902 |
893 scope.apply(() { | 903 scope.apply(() { |
894 scope.context['selected'] = scope.context['values'][0]; | 904 scope.context['selected'] = scope.context['values'][0]['items'][1]
['val']; |
895 }); | 905 }); |
896 | 906 |
897 expect(element.value).toEqual('0'); | 907 expect(element.value).toEqual('c'); |
898 }); | 908 }); |
899 | 909 |
900 | 910 |
901 it('should bind to scope value through experession', () { | 911 it('should bind to scope value through experession', () { |
902 createSelect({'ng-model': 'selected'}, null, null, 'item in values',
'item.name', 'item.id'); | 912 createSelect({'ng-model': 'selected'}, null, null, 'item in values',
'item.name', 'item.id'); |
903 | 913 |
904 scope.apply(() { | 914 scope.apply(() { |
905 scope.context['values'] = [{'id': 10, 'name': 'A'}, {'id': 20, 'na
me': 'B'}]; | 915 scope.context['values'] = [{'id': 10, 'name': 'A'}, {'id': 20, 'na
me': 'B'}]; |
906 scope.context['selected'] = scope.context['values'][0]['id']; | 916 scope.context['selected'] = scope.context['values'][0]['id']; |
907 }); | 917 }); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 }, true); | 1230 }, true); |
1221 | 1231 |
1222 | 1232 |
1223 scope.apply(() { | 1233 scope.apply(() { |
1224 scope.context['values'] = [{'name': 'A', 'id': 1}, {'name': 'B', '
id': 2}]; | 1234 scope.context['values'] = [{'name': 'A', 'id': 1}, {'name': 'B', '
id': 2}]; |
1225 scope.context['required'] = false; | 1235 scope.context['required'] = false; |
1226 }); | 1236 }); |
1227 | 1237 |
1228 element.value = ''; | 1238 element.value = ''; |
1229 _.triggerEvent(element, 'change'); | 1239 _.triggerEvent(element, 'change'); |
1230 expect(element).toEqualValid(); | 1240 expect(element).toBeValid(); |
1231 | 1241 |
1232 scope.apply(() { | 1242 scope.apply(() { |
1233 scope.context['required'] = true; | 1243 scope.context['required'] = true; |
1234 }); | 1244 }); |
1235 expect(element).toEqualInvalid(); | 1245 expect(element).not.toBeValid(); |
1236 | 1246 |
1237 scope.apply(() { | 1247 scope.apply(() { |
1238 scope.context['value'] = scope.context['values'][0]; | 1248 scope.context['value'] = scope.context['values'][0]; |
1239 }); | 1249 }); |
1240 expect(element).toEqualValid(); | 1250 expect(element).toBeValid(); |
1241 | 1251 |
1242 element.value = ''; | 1252 element.value = ''; |
1243 _.triggerEvent(element, 'change'); | 1253 _.triggerEvent(element, 'change'); |
1244 expect(element).toEqualInvalid(); | 1254 expect(element).not.toBeValid(); |
1245 | 1255 |
1246 scope.apply(() { | 1256 scope.apply(() { |
1247 scope.context['required'] = false; | 1257 scope.context['required'] = false; |
1248 }); | 1258 }); |
1249 expect(element).toEqualValid(); | 1259 expect(element).toBeValid(); |
1250 }); | 1260 }); |
1251 }); | 1261 }); |
1252 }); | 1262 }); |
1253 | 1263 |
1254 | 1264 |
1255 describe('option', () { | 1265 describe('option', () { |
1256 | 1266 |
1257 it('should populate value attribute on OPTION', () { | 1267 it('should populate value attribute on OPTION', () { |
1258 compile('<select ng-model="x"><option selected>abc</option></select>')
; | 1268 compile('<select ng-model="x"><option selected>abc</option></select>')
; |
1259 expect(element).toEqualSelect([['?'], 'abc']); | 1269 expect(element).toEqualSelect([['?'], 'abc']); |
1260 }); | 1270 }); |
1261 | 1271 |
1262 it('should ignore value if already exists', () { | 1272 it('should ignore value if already exists', () { |
1263 compile('<select ng-model="x"><option value="abc">xyz</option></select
>'); | 1273 compile('<select ng-model="x"><option value="abc">xyz</option></select
>'); |
1264 expect(element).toEqualSelect([['?'], 'abc']); | 1274 expect(element).toEqualSelect([['?'], 'abc']); |
1265 }); | 1275 }); |
1266 | 1276 |
1267 it('should set value even if self closing HTML', () { | 1277 it('should set value even if self closing HTML', () { |
1268 scope.context['x'] = 'hello'; | 1278 scope.context['x'] = 'hello'; |
1269 compile('<select ng-model="x"><option>hello</select>'); | 1279 compile('<select ng-model="x"><option>hello</select>'); |
1270 expect(element).toEqualSelect([['hello']]); | 1280 expect(element).toEqualSelect([['hello']]); |
1271 }); | 1281 }); |
1272 | 1282 |
1273 it('should not blow up when option directive is found inside of a datali
st', | 1283 it('should not blow up when option directive is found inside of a datali
st', |
1274 () { | 1284 () { |
1275 _.compile('<div>' + | 1285 _.compile('<div>' |
1276 '<datalist><option>some val</option></datalist>' + | 1286 '<datalist><option>some val</option></datalist>' |
1277 '<span>{{foo}}</span>' + | 1287 '<span>{{foo}}</span>' |
1278 '</div>'); | 1288 '</div>'); |
1279 | 1289 |
1280 _.rootScope.context['foo'] = 'success'; | 1290 _.rootScope.context['foo'] = 'success'; |
1281 _.rootScope.apply(); | 1291 _.rootScope.apply(); |
1282 expect(_.rootElement.querySelector('span').text).toEqual('success'); | 1292 expect(_.rootElement.querySelector('span').text).toEqual('success'); |
1283 }); | 1293 }); |
1284 }); | 1294 }); |
1285 }); | 1295 }); |
1286 }); | 1296 }); |
1287 } | 1297 } |
OLD | NEW |