@@ -168,6 +168,8 @@ describe('ui-select tests', function() {
168168 if ( attrs . refresh !== undefined ) { choicesAttrsHtml += ' refresh="' + attrs . refresh + '"' ; }
169169 if ( attrs . refreshDelay !== undefined ) { choicesAttrsHtml += ' refresh-delay="' + attrs . refreshDelay + '"' ; }
170170 if ( attrs . backspaceReset !== undefined ) { attrsHtml += ' backspace-reset="' + attrs . backspaceReset + '"' ; }
171+ if ( attrs . uiDisableChoice !== undefined ) { choicesAttrsHtml += ' ui-disable-choice="' + attrs . uiDisableChoice + '"' ; }
172+ if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
171173 }
172174
173175 return compileTemplate (
@@ -1837,11 +1839,13 @@ describe('ui-select tests', function() {
18371839 if ( attrs . taggingLabel !== undefined ) { attrsHtml += ' tagging-label="' + attrs . taggingLabel + '"' ; }
18381840 if ( attrs . inputId !== undefined ) { attrsHtml += ' input-id="' + attrs . inputId + '"' ; }
18391841 if ( attrs . groupBy !== undefined ) { choicesAttrsHtml += ' group-by="' + attrs . groupBy + '"' ; }
1842+ if ( attrs . uiDisableChoice !== undefined ) { choicesAttrsHtml += ' ui-disable-choice="' + attrs . uiDisableChoice + '"' ; }
18401843 if ( attrs . lockChoice !== undefined ) { matchesAttrsHtml += ' ui-lock-choice="' + attrs . lockChoice + '"' ; }
18411844 if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
18421845 if ( attrs . resetSearchInput !== undefined ) { attrsHtml += ' reset-search-input="' + attrs . resetSearchInput + '"' ; }
18431846 if ( attrs . limit !== undefined ) { attrsHtml += ' limit="' + attrs . limit + '"' ; }
18441847 if ( attrs . onSelect !== undefined ) { attrsHtml += ' on-select="' + attrs . onSelect + '"' ; }
1848+ if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
18451849 }
18461850
18471851 return compileTemplate (
@@ -2832,6 +2836,61 @@ describe('ui-select tests', function() {
28322836 expect ( el . scope ( ) . $select . selected . length ) . toEqual ( 2 ) ;
28332837 } ) ;
28342838
2839+ describe ( 'Test key down key up and activeIndex should skip disabled choice for uiMultipleSelect' , function ( ) {
2840+ it ( 'should ignored disabled items going up' , function ( ) {
2841+ var el = createUiSelect ( { uiDisableChoice :"person.age == 12" } ) ;
2842+ openDropdown ( el ) ;
2843+ var searchInput = el . find ( '.ui-select-search' ) ;
2844+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 0 ) ;
2845+ triggerKeydown ( searchInput , Key . Down ) ;
2846+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
2847+ triggerKeydown ( searchInput , Key . Up ) ;
2848+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 0 ) ;
2849+ } ) ;
2850+
2851+ it ( 'should ignored disabled items going up with tagging on' , function ( ) {
2852+ var el = createUiSelectMultiple ( { uiDisableChoice :"person.age == 12" , tagging :true } ) ;
2853+ openDropdown ( el ) ;
2854+ var searchInput = el . find ( '.ui-select-search' ) ;
2855+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( - 1 ) ;
2856+ triggerKeydown ( searchInput , Key . Down ) ;
2857+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
2858+ triggerKeydown ( searchInput , Key . Up ) ;
2859+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( - 1 ) ;
2860+ } ) ;
2861+
2862+ it ( 'should ignored disabled items going down' , function ( ) {
2863+ var el = createUiSelectMultiple ( { uiDisableChoice :"person.age == 12" } ) ;
2864+ openDropdown ( el ) ;
2865+ var searchInput = el . find ( '.ui-select-search' ) ;
2866+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 0 ) ;
2867+ triggerKeydown ( searchInput , Key . Down ) ;
2868+ triggerKeydown ( searchInput , Key . Enter ) ;
2869+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
2870+ } ) ;
2871+
2872+ it ( 'should ignored disabled items going down with tagging on' , function ( ) {
2873+ var el = createUiSelectMultiple ( { uiDisableChoice :"person.age == 12" , tagging :true } ) ;
2874+ openDropdown ( el ) ;
2875+ var searchInput = el . find ( '.ui-select-search' ) ;
2876+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( - 1 ) ;
2877+ triggerKeydown ( searchInput , Key . Down ) ;
2878+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
2879+ triggerKeydown ( searchInput , Key . Up ) ;
2880+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( - 1 ) ;
2881+ } ) ;
2882+
2883+ it ( 'should ignore disabled items, going down with remove-selected on false' , function ( ) {
2884+ var el = createUiSelectMultiple ( { uiDisableChoice :"person.age == 12" , removeSelected :false } ) ;
2885+ openDropdown ( el ) ;
2886+ var searchInput = el . find ( '.ui-select-search' ) ;
2887+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 0 ) ;
2888+ triggerKeydown ( searchInput , Key . Down ) ;
2889+ triggerKeydown ( searchInput , Key . Enter ) ;
2890+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
2891+ } ) ;
2892+ } ) ;
2893+
28352894 describe ( 'resetSearchInput option multiple' , function ( ) {
28362895 it ( 'should be true by default' , function ( ) {
28372896 expect ( createUiSelectMultiple ( ) . scope ( ) . $select . resetSearchInput ) . toBe ( true ) ;
@@ -2842,6 +2901,7 @@ describe('ui-select tests', function() {
28422901 } ) ;
28432902 } ) ;
28442903
2904+
28452905 describe ( 'Reset the search value' , function ( ) {
28462906 it ( 'should clear the search input when resetSearchInput is true' , function ( ) {
28472907 var el = createUiSelectMultiple ( ) ;
@@ -3107,7 +3167,7 @@ describe('ui-select tests', function() {
31073167
31083168 describe ( 'Test Spinner for promises' , function ( ) {
31093169 var deferred ;
3110-
3170+
31113171 function getFromServer ( ) {
31123172 deferred = $q . defer ( ) ;
31133173 return deferred . promise ;
@@ -3130,14 +3190,14 @@ describe('ui-select tests', function() {
31303190 it ( 'should have set a custom class value of randomclass' , function ( ) {
31313191 var control = createUiSelect ( { spinnerClass : 'randomclass' } ) ;
31323192 expect ( control . scope ( ) . $select . spinnerClass ) . toEqual ( 'randomclass' ) ;
3133- } ) ;
3193+ } ) ;
31343194
31353195 it ( 'should not display spinner when disabled' , function ( ) {
31363196 scope . getFromServer = getFromServer ;
31373197 var el = createUiSelect ( { theme : 'bootstrap' , refresh :"getFromServer($select.search)" , refreshDelay :0 } ) ;
31383198 openDropdown ( el ) ;
31393199 var spinner = el . find ( '.ui-select-refreshing' ) ;
3140- expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
3200+ expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
31413201 setSearchText ( el , 'a' ) ;
31423202 expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
31433203 deferred . resolve ( ) ;
@@ -3150,7 +3210,7 @@ describe('ui-select tests', function() {
31503210 var el = createUiSelect ( { spinnerEnabled : true , theme : 'bootstrap' , refresh :"getFromServer($select.search)" , refreshDelay :0 } ) ;
31513211 openDropdown ( el ) ;
31523212 var spinner = el . find ( '.ui-select-refreshing' ) ;
3153- expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
3213+ expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
31543214 setSearchText ( el , 'a' ) ;
31553215 expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( false ) ;
31563216 deferred . resolve ( ) ;
@@ -3167,4 +3227,68 @@ describe('ui-select tests', function() {
31673227 } ) ;
31683228 } ) ;
31693229
3230+ describe ( 'Test key down key up and activeIndex should skip disabled choice' , function ( ) {
3231+ it ( 'should ignore disabled items, going down' , function ( ) {
3232+ var el = createUiSelect ( { uiDisableChoice :"person.age == 12" } ) ;
3233+ openDropdown ( el ) ;
3234+ var searchInput = el . find ( '.ui-select-search' ) ;
3235+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 0 ) ;
3236+ triggerKeydown ( searchInput , Key . Down ) ;
3237+ triggerKeydown ( searchInput , Key . Enter ) ;
3238+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
3239+ } ) ;
3240+
3241+ it ( 'should ignore disabled items, going up' , function ( ) {
3242+ var el = createUiSelect ( { uiDisableChoice :"person.age == 12" } ) ;
3243+ openDropdown ( el ) ;
3244+ var searchInput = el . find ( '.ui-select-search' ) ;
3245+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 0 ) ;
3246+ triggerKeydown ( searchInput , Key . Down ) ;
3247+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
3248+ triggerKeydown ( searchInput , Key . Up ) ;
3249+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 0 ) ;
3250+ } ) ;
3251+
3252+ it ( 'should ignored disabled items going up with tagging on' , function ( ) {
3253+ var el = createUiSelect ( { uiDisableChoice :"person.age == 12" , tagging :true } ) ;
3254+ openDropdown ( el ) ;
3255+ var searchInput = el . find ( '.ui-select-search' ) ;
3256+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( - 1 ) ;
3257+ triggerKeydown ( searchInput , Key . Down ) ;
3258+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
3259+ triggerKeydown ( searchInput , Key . Up ) ;
3260+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( - 1 ) ;
3261+ } ) ;
3262+
3263+ it ( 'should ignored disabled items in the down direction with tagging on' , function ( ) {
3264+ var el = createUiSelect ( { uiDisableChoice :"person.age == 12" , tagging :true } ) ;
3265+ openDropdown ( el ) ;
3266+ var searchInput = el . find ( '.ui-select-search' ) ;
3267+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( - 1 ) ;
3268+ triggerKeydown ( searchInput , Key . Down ) ;
3269+ triggerKeydown ( searchInput , Key . Enter ) ;
3270+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
3271+ } ) ;
3272+
3273+ it ( 'should ignored disabled items going up with tagging on and custom tag' , function ( ) {
3274+ var el = createUiSelect ( { uiDisableChoice :"person.age == 12" , tagging :true , taggingLabel :'custom tag' } ) ;
3275+ openDropdown ( el ) ;
3276+ var searchInput = el . find ( '.ui-select-search' ) ;
3277+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( - 1 ) ;
3278+ triggerKeydown ( searchInput , Key . Down ) ;
3279+ triggerKeydown ( searchInput , Key . Enter ) ;
3280+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
3281+ } ) ;
3282+
3283+ it ( 'should ignore disabled items, going down with remove-selected on false' , function ( ) {
3284+ var el = createUiSelect ( { uiDisableChoice :"person.age == 12" , removeSelected :false } ) ;
3285+ openDropdown ( el ) ;
3286+ var searchInput = el . find ( '.ui-select-search' ) ;
3287+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 0 ) ;
3288+ triggerKeydown ( searchInput , Key . Down ) ;
3289+ triggerKeydown ( searchInput , Key . Enter ) ;
3290+ expect ( el . scope ( ) . $select . activeIndex ) . toBe ( 2 ) ;
3291+ } ) ;
3292+ } ) ;
3293+
31703294} ) ;
0 commit comments