@@ -964,22 +964,79 @@ describe('select', function() {
964
964
965
965
describe ( 'option' , function ( ) {
966
966
967
- it ( 'should populate value attribute on OPTION ' , function ( ) {
967
+ it ( 'should populate a missing value attribute with the option text ' , function ( ) {
968
968
compile ( '<select ng-model="x"><option selected>abc</option></select>' ) ;
969
969
expect ( element ) . toEqualSelect ( [ unknownValue ( undefined ) ] , 'abc' ) ;
970
970
} ) ;
971
971
972
- it ( 'should ignore value if already exists' , function ( ) {
972
+
973
+ it ( 'should ignore the option text if the value attribute exists' , function ( ) {
973
974
compile ( '<select ng-model="x"><option value="abc">xyz</option></select>' ) ;
974
975
expect ( element ) . toEqualSelect ( [ unknownValue ( undefined ) ] , 'abc' ) ;
975
976
} ) ;
976
977
978
+
977
979
it ( 'should set value even if self closing HTML' , function ( ) {
978
980
scope . x = 'hello' ;
979
981
compile ( '<select ng-model="x"><option>hello</select>' ) ;
980
982
expect ( element ) . toEqualSelect ( [ 'hello' ] ) ;
981
983
} ) ;
982
984
985
+
986
+ it ( 'should add options with interpolated value attributes' ,
987
+ inject ( function ( $rootScope , $compile ) {
988
+ var scope = $rootScope ;
989
+
990
+ scope . option1 = 'option1' ;
991
+ scope . option2 = 'option2' ;
992
+
993
+ var element = $compile (
994
+ '<select ng-model="selected">' +
995
+ '<option value="{{option1}}">Option 1</option>' +
996
+ '<option value="{{option2}}">Option 2</option>' +
997
+ '</div>' ) ( scope ) ;
998
+
999
+ scope . $digest ( ) ;
1000
+ expect ( scope . selected ) . toBeUndefined ( ) ;
1001
+
1002
+ browserTrigger ( element . find ( 'option' ) . eq ( 0 ) ) ;
1003
+ expect ( scope . selected ) . toBe ( 'option1' ) ;
1004
+
1005
+ scope . selected = 'option2' ;
1006
+ scope . $digest ( ) ;
1007
+ expect ( element . find ( 'option' ) . eq ( 1 ) . prop ( 'selected' ) ) . toBe ( true ) ;
1008
+ expect ( element . find ( 'option' ) . eq ( 1 ) . text ( ) ) . toBe ( 'Option 2' ) ;
1009
+ } )
1010
+ ) ;
1011
+
1012
+
1013
+ it ( 'should update the option when the interpolated value attribute changes' ,
1014
+ inject ( function ( $rootScope , $compile ) {
1015
+ var scope = $rootScope ;
1016
+
1017
+ scope . option1 = 'option1' ;
1018
+ scope . option2 = 'option2' ;
1019
+
1020
+ var element = $compile (
1021
+ '<select ng-model="selected">' +
1022
+ '<option value="{{option1}}">Option 1</option>' +
1023
+ '<option value="{{option2}}">Option 2</option>' +
1024
+ '</div>' ) ( scope ) ;
1025
+
1026
+ scope . $digest ( ) ;
1027
+ expect ( scope . selected ) . toBeUndefined ( ) ;
1028
+
1029
+ //Change value of option2
1030
+ scope . option2 = 'option2Changed' ;
1031
+
1032
+ scope . selected = 'option2Changed' ;
1033
+ scope . $digest ( ) ;
1034
+ expect ( element . find ( 'option' ) . eq ( 1 ) . prop ( 'selected' ) ) . toBe ( true ) ;
1035
+ expect ( element . find ( 'option' ) . eq ( 1 ) . text ( ) ) . toBe ( 'Option 2' ) ;
1036
+ } )
1037
+ ) ;
1038
+
1039
+
983
1040
it ( 'should not blow up when option directive is found inside of a datalist' ,
984
1041
inject ( function ( $compile , $rootScope ) {
985
1042
var element = $compile ( '<div>' +
@@ -993,6 +1050,7 @@ describe('select', function() {
993
1050
dealoc ( element ) ;
994
1051
} ) ) ;
995
1052
1053
+
996
1054
it ( 'should throw an exception if an option value interpolates to "hasOwnProperty"' , function ( ) {
997
1055
scope . hasOwnPropertyOption = "hasOwnProperty" ;
998
1056
expect ( function ( ) {
0 commit comments