@@ -94,7 +94,6 @@ describe('Typeahead', function() {
94
94
var that = this ;
95
95
waitsForAndRuns ( function ( ) { return that . dropdown . close . calls . count ( ) ; } , done , 100 ) ;
96
96
} ) ;
97
-
98
97
} ) ;
99
98
100
99
describe ( 'when dropdown triggers suggestionClicked with undefined displayKey' , function ( ) {
@@ -871,17 +870,69 @@ describe('Typeahead', function() {
871
870
} ) ;
872
871
873
872
describe ( 'when set autoWidth option' , function ( ) {
874
- it ( 'should set default to true' , function ( ) {
873
+ it ( 'should set default to true' , function ( ) {
875
874
this . dropdown . trigger ( 'redrawn' ) ;
876
875
expect ( this . view . autoWidth ) . toBeTruthy ( ) ;
877
876
expect ( / \d { 3 } p x / . test ( this . view . $node [ 0 ] . style . width ) ) . toBeTruthy ( ) ;
878
877
} ) ;
879
878
880
- it ( 'should not put width style when autoWidth is false' , function ( ) {
879
+ it ( 'should not put width style when autoWidth is false' , function ( ) {
881
880
this . view . autoWidth = false ;
882
881
this . dropdown . trigger ( 'redrawn' ) ;
883
882
expect ( this . view . autoWidth ) . toBeFalsy ( ) ;
884
883
expect ( this . view . $node [ 0 ] . style . width ) . toBeFalsy ( ) ;
885
884
} ) ;
886
885
} ) ;
886
+
887
+ describe ( 'when ariaLabelledBy is set' , function ( ) {
888
+ beforeEach ( function ( ) {
889
+ this . view . destroy ( ) ;
890
+ } ) ;
891
+
892
+ describe ( 'when set to a specific id' , function ( ) {
893
+ it ( 'should set aria-labelledby to the specified id' , function ( ) {
894
+ this . view = new Typeahead ( {
895
+ input : this . $input ,
896
+ ariaLabelledBy : 'custom-id-attr'
897
+ } ) ;
898
+
899
+ expect ( this . $input . attr ( 'aria-labelledby' ) ) . toBe ( 'custom-id-attr' ) ;
900
+ } ) ;
901
+ } ) ;
902
+
903
+ describe ( 'when set to false' , function ( ) {
904
+ it ( 'should set aria-labelledby to null' , function ( ) {
905
+ this . view = new Typeahead ( {
906
+ input : this . $input ,
907
+ ariaLabelledBy : false
908
+ } ) ;
909
+
910
+ expect ( this . $input . attr ( 'aria-labelledby' ) ) . toBeUndefined ( ) ;
911
+ } ) ;
912
+ } ) ;
913
+
914
+ describe ( 'when not set' , function ( ) {
915
+ beforeEach ( function ( ) {
916
+ this . $input . attr ( 'id' , 'custom-input-id' ) ;
917
+ } ) ;
918
+
919
+ it ( 'should set aria-labelledby to null if no placeholder specified' , function ( ) {
920
+ this . view = new Typeahead ( {
921
+ input : this . $input
922
+ } ) ;
923
+
924
+ expect ( this . $input . attr ( 'aria-labelledby' ) ) . toBeUndefined ( ) ;
925
+ } ) ;
926
+
927
+ it ( 'should set aria-labelledby to the input id if a placeholder is specified' , function ( ) {
928
+ this . $input . attr ( 'placeholder' , 'custom placeholder' ) ;
929
+
930
+ this . view = new Typeahead ( {
931
+ input : this . $input
932
+ } ) ;
933
+
934
+ expect ( this . $input . attr ( 'aria-labelledby' ) ) . toBe ( 'custom-input-id' ) ;
935
+ } ) ;
936
+ } ) ;
937
+ } ) ;
887
938
} ) ;
0 commit comments