@@ -1819,6 +1819,8 @@ describe('ui-select tests', function() {
1819
1819
if ( attrs . lockChoice !== undefined ) { matchesAttrsHtml += ' ui-lock-choice="' + attrs . lockChoice + '"' ; }
1820
1820
if ( attrs . removeSelected !== undefined ) { attrsHtml += ' remove-selected="' + attrs . removeSelected + '"' ; }
1821
1821
if ( attrs . resetSearchInput !== undefined ) { attrsHtml += ' reset-search-input="' + attrs . resetSearchInput + '"' ; }
1822
+ if ( attrs . limit !== undefined ) { attrsHtml += ' limit="' + attrs . limit + '"' ; }
1823
+ if ( attrs . onSelect !== undefined ) { attrsHtml += ' on-select="' + attrs . onSelect + '"' ; }
1822
1824
}
1823
1825
1824
1826
return compileTemplate (
@@ -2764,6 +2766,49 @@ describe('ui-select tests', function() {
2764
2766
expect ( el . scope ( ) . $select . selected . length ) . toBe ( 2 ) ;
2765
2767
} ) ;
2766
2768
2769
+ it ( 'should set only 1 item in the selected items when limit = 1' , function ( ) {
2770
+ var el = createUiSelectMultiple ( { limit : 1 } ) ;
2771
+ clickItem ( el , 'Wladimir' ) ;
2772
+ clickItem ( el , 'Natasha' ) ;
2773
+ expect ( el . scope ( ) . $select . selected . length ) . toEqual ( 1 ) ;
2774
+ } ) ;
2775
+
2776
+ it ( 'should only have 1 item selected and onSelect function should only be handled once.' , function ( ) {
2777
+ scope . onSelectFn = function ( $item , $model ) {
2778
+ scope . $item = $item ;
2779
+ scope . $model = $model ;
2780
+ } ;
2781
+ var el = createUiSelectMultiple ( { limit :1 , onSelect :'onSelectFn($item, $model)' } ) ;
2782
+
2783
+ expect ( scope . $item ) . toBeFalsy ( ) ;
2784
+ expect ( scope . $model ) . toBeFalsy ( ) ;
2785
+
2786
+ clickItem ( el , 'Samantha' ) ;
2787
+ $timeout . flush ( ) ;
2788
+ clickItem ( el , 'Natasha' ) ;
2789
+ $timeout . flush ( ) ;
2790
+ expect ( scope . selection . selectedMultiple [ 0 ] . name ) . toBe ( 'Samantha' ) ;
2791
+ expect ( scope . $model . name ) . toEqual ( 'Samantha' ) ;
2792
+ expect ( el . scope ( ) . $select . selected . length ) . toEqual ( 1 ) ;
2793
+ } ) ;
2794
+
2795
+ it ( 'should only have 2 items selected and onSelect function should be handeld.' , function ( ) {
2796
+ scope . onSelectFn = function ( $item , $model ) {
2797
+ scope . $item = $item ;
2798
+ scope . $model = $model ;
2799
+ } ;
2800
+ var el = createUiSelectMultiple ( { onSelect :'onSelectFn($item, $model)' } ) ;
2801
+
2802
+ expect ( scope . $item ) . toBeFalsy ( ) ;
2803
+ expect ( scope . $model ) . toBeFalsy ( ) ;
2804
+
2805
+ clickItem ( el , 'Samantha' ) ;
2806
+ $timeout . flush ( ) ;
2807
+ clickItem ( el , 'Natasha' ) ;
2808
+ $timeout . flush ( ) ;
2809
+ expect ( el . scope ( ) . $select . selected . length ) . toEqual ( 2 ) ;
2810
+ } ) ;
2811
+
2767
2812
describe ( 'resetSearchInput option multiple' , function ( ) {
2768
2813
it ( 'should be true by default' , function ( ) {
2769
2814
expect ( createUiSelectMultiple ( ) . scope ( ) . $select . resetSearchInput ) . toBe ( true ) ;
0 commit comments