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