@@ -771,7 +771,7 @@ describe('ngOptions', function() {
771
771
} ) ;
772
772
773
773
774
- it ( 'should not select disabled options when model changes' , function ( ) {
774
+ it ( 'should select disabled options when model changes' , function ( ) {
775
775
scope . options = [
776
776
{ name : 'white' , value : '#FFFFFF' } ,
777
777
{ name : 'one' , value : 1 , unavailable : true } ,
@@ -792,11 +792,14 @@ describe('ngOptions', function() {
792
792
scope . $apply ( 'selected = 1' ) ;
793
793
options = element . find ( 'option' ) ;
794
794
795
- expect ( element . val ( ) ) . toEqualUnknownValue ( '?' ) ;
796
- expect ( options . length ) . toEqual ( 5 ) ;
797
- expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
795
+ // jQuery returns null for val() when the option is disabled, see
796
+ // https://bugs.jquery.com/ticket/13097
797
+ expect ( element [ 0 ] . value ) . toBe ( 'number:1' ) ;
798
+ expect ( options . length ) . toEqual ( 4 ) ;
799
+ expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
800
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
798
801
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
799
- expect ( options . eq ( 4 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
802
+ expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
800
803
} ) ;
801
804
802
805
@@ -816,11 +819,14 @@ describe('ngOptions', function() {
816
819
scope . $apply ( 'selected = 1' ) ;
817
820
var options = element . find ( 'option' ) ;
818
821
819
- expect ( element . val ( ) ) . toEqualUnknownValue ( '?' ) ;
820
- expect ( options . length ) . toEqual ( 5 ) ;
821
- expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
822
+ // jQuery returns null for val() when the option is disabled, see
823
+ // https://bugs.jquery.com/ticket/13097
824
+ expect ( element [ 0 ] . value ) . toBe ( 'number:1' ) ;
825
+ expect ( options . length ) . toEqual ( 4 ) ;
826
+ expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
827
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
822
828
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
823
- expect ( options . eq ( 4 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
829
+ expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
824
830
825
831
// Now enable that option
826
832
scope . $apply ( function ( ) {
@@ -861,7 +867,7 @@ describe('ngOptions', function() {
861
867
} ) ;
862
868
863
869
864
- it ( 'should not select disabled options when model changes' , function ( ) {
870
+ it ( 'should select disabled options when model changes' , function ( ) {
865
871
scope . options = [
866
872
{ name : 'a' , value : 0 } ,
867
873
{ name : 'b' , value : 1 , unavailable : true } ,
@@ -886,14 +892,14 @@ describe('ngOptions', function() {
886
892
scope . $apply ( 'selected = [1,3]' ) ;
887
893
options = element . find ( 'option' ) ;
888
894
expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
889
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
895
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
890
896
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
891
897
expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
892
898
893
899
// Now only select the disabled option
894
900
scope . $apply ( 'selected = [1]' ) ;
895
901
expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
896
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
902
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
897
903
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
898
904
expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
899
905
} ) ;
@@ -917,7 +923,7 @@ describe('ngOptions', function() {
917
923
var options = element . find ( 'option' ) ;
918
924
919
925
expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
920
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
926
+ expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
921
927
expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
922
928
expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
923
929
@@ -2535,37 +2541,6 @@ describe('ngOptions', function() {
2535
2541
expect ( element . find ( 'option' ) [ 1 ] . selected ) . toBeTruthy ( ) ;
2536
2542
} ) ;
2537
2543
2538
- it ( 'should not write disabled selections from model' , function ( ) {
2539
- scope . selected = [ 30 ] ;
2540
- scope . options = [
2541
- { name : 'white' , value : '#FFFFFF' } ,
2542
- { name : 'one' , value : 1 , unavailable : true } ,
2543
- { name : 'notTrue' , value : false } ,
2544
- { name : 'thirty' , value : 30 , unavailable : false }
2545
- ] ;
2546
- createSelect ( {
2547
- 'ng-options' : 'o.value as o.name disable when o.unavailable for o in options' ,
2548
- 'ng-model' : 'selected' ,
2549
- 'multiple' : true
2550
- } ) ;
2551
-
2552
- var options = element . find ( 'option' ) ;
2553
-
2554
- expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2555
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2556
- expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2557
- expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
2558
-
2559
- scope . $apply ( function ( ) {
2560
- scope . selected . push ( 1 ) ;
2561
- } ) ;
2562
-
2563
- expect ( options . eq ( 0 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2564
- expect ( options . eq ( 1 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2565
- expect ( options . eq ( 2 ) . prop ( 'selected' ) ) . toEqual ( false ) ;
2566
- expect ( options . eq ( 3 ) . prop ( 'selected' ) ) . toEqual ( true ) ;
2567
- } ) ;
2568
-
2569
2544
2570
2545
it ( 'should update model on change' , function ( ) {
2571
2546
createMultiSelect ( ) ;
0 commit comments