@@ -212,6 +212,12 @@ describe('ui-select tests', function() {
212
212
scope . $digest ( ) ;
213
213
}
214
214
215
+ function showChoicesForSearch ( el , search ) {
216
+ setSearchText ( el , search ) ;
217
+ el . scope ( ) . $select . searchInput . trigger ( 'keyup' ) ;
218
+ scope . $digest ( ) ;
219
+ }
220
+
215
221
216
222
// Tests
217
223
//uisRepeatParser
@@ -561,7 +567,7 @@ describe('ui-select tests', function() {
561
567
var el = createUiSelect ( { tagging : 'taggingFunc' } ) ;
562
568
clickMatch ( el ) ;
563
569
564
- $ ( el ) . scope ( ) . $select . search = 'idontexist' ;
570
+ showChoicesForSearch ( el , 'idontexist' ) ;
565
571
$ ( el ) . scope ( ) . $select . activeIndex = 0 ;
566
572
$ ( el ) . scope ( ) . $select . select ( 'idontexist' ) ;
567
573
@@ -1581,7 +1587,8 @@ describe('ui-select tests', function() {
1581
1587
describe ( 'multi selection' , function ( ) {
1582
1588
1583
1589
function createUiSelectMultiple ( attrs ) {
1584
- var attrsHtml = '' ;
1590
+ var attrsHtml = '' ,
1591
+ choicesAttrsHtml = '' ;
1585
1592
if ( attrs !== undefined ) {
1586
1593
if ( attrs . disabled !== undefined ) { attrsHtml += ' ng-disabled="' + attrs . disabled + '"' ; }
1587
1594
if ( attrs . required !== undefined ) { attrsHtml += ' ng-required="' + attrs . required + '"' ; }
@@ -1590,12 +1597,13 @@ describe('ui-select tests', function() {
1590
1597
if ( attrs . tagging !== undefined ) { attrsHtml += ' tagging="' + attrs . tagging + '"' ; }
1591
1598
if ( attrs . taggingTokens !== undefined ) { attrsHtml += ' tagging-tokens="' + attrs . taggingTokens + '"' ; }
1592
1599
if ( attrs . inputId !== undefined ) { attrsHtml += ' input-id="' + attrs . inputId + '"' ; }
1600
+ if ( attrs . groupBy !== undefined ) { choicesAttrsHtml += ' group-by="' + attrs . groupBy + '"' ; }
1593
1601
}
1594
1602
1595
1603
return compileTemplate (
1596
1604
'<ui-select multiple ng-model="selection.selectedMultiple"' + attrsHtml + ' theme="bootstrap" style="width: 800px;"> \
1597
1605
<ui-select-match placeholder="Pick one...">{{$item.name}} <{{$item.email}}></ui-select-match> \
1598
- <ui-select-choices repeat="person in people | filter: $select.search"> \
1606
+ <ui-select-choices repeat="person in people | filter: $select.search"' + choicesAttrsHtml + ' > \
1599
1607
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1600
1608
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1601
1609
</ui-select-choices> \
@@ -2206,6 +2214,69 @@ describe('ui-select tests', function() {
2206
2214
expect ( el . scope ( ) . $select . multiple ) . toBe ( true ) ;
2207
2215
} ) ;
2208
2216
2217
+ it ( 'should not call tagging function needlessly' , function ( ) {
2218
+ scope . slowTaggingFunc = function ( name ) {
2219
+ // for (var i = 0; i < 100000000; i++);
2220
+ return { name : name } ;
2221
+ } ;
2222
+ spyOn ( scope , 'slowTaggingFunc' ) . and . callThrough ( ) ;
2223
+
2224
+ var el = createUiSelectMultiple ( { tagging : 'slowTaggingFunc' } ) ;
2225
+
2226
+ showChoicesForSearch ( el , 'Foo' ) ;
2227
+ expect ( el . find ( '.ui-select-choices-row-inner' ) . size ( ) ) . toBe ( 6 ) ;
2228
+
2229
+ showChoicesForSearch ( el , 'a' ) ;
2230
+ expect ( el . find ( '.ui-select-choices-row-inner' ) . size ( ) ) . toBe ( 9 ) ;
2231
+
2232
+ expect ( scope . slowTaggingFunc . calls . count ( ) ) . toBe ( 2 ) ;
2233
+ expect ( scope . slowTaggingFunc . calls . count ( ) ) . not . toBe ( 15 ) ;
2234
+ } ) ;
2235
+
2236
+ it ( 'should allow decline tags when tagging function returns null in multiple select mode' , function ( ) {
2237
+ scope . taggingFunc = function ( name ) {
2238
+ if ( name == 'idontexist' ) return null ;
2239
+ return {
2240
+ name : name ,
2241
+ email : name + '@email.com' ,
2242
+ group : 'Foo' ,
2243
+ age : 12
2244
+ } ;
2245
+ } ;
2246
+
2247
+ var el = createUiSelectMultiple ( { tagging : 'taggingFunc' } ) ;
2248
+
2249
+ showChoicesForSearch ( el , 'amalie' ) ;
2250
+ expect ( el . find ( '.ui-select-choices-row-inner' ) . size ( ) ) . toBe ( 2 ) ;
2251
+ expect ( el . scope ( ) . $select . items [ 0 ] ) . toEqual ( jasmine . objectContaining ( { name : 'amalie' , isTag : true } ) ) ;
2252
+ expect ( el . scope ( ) . $select . items [ 1 ] ) . toEqual ( jasmine . objectContaining ( { name : 'Amalie' } ) ) ;
2253
+
2254
+ showChoicesForSearch ( el , 'idoexist' ) ;
2255
+ expect ( el . find ( '.ui-select-choices-row-inner' ) . size ( ) ) . toBe ( 1 ) ;
2256
+ expect ( el . find ( '.ui-select-choices-row-inner' ) . is ( ':contains(idoexist@email.com)' ) ) . toBeTruthy ( ) ;
2257
+
2258
+ showChoicesForSearch ( el , 'idontexist' ) ;
2259
+ expect ( el . find ( '.ui-select-choices-row-inner' ) . size ( ) ) . toBe ( 0 ) ;
2260
+ } ) ;
2261
+
2262
+ it ( 'should allow creating tag in multi select mode with tagging and group-by enabled' , function ( ) {
2263
+ scope . taggingFunc = function ( name ) {
2264
+ return {
2265
+ name : name ,
2266
+ email : name + '@email.com' ,
2267
+ group : 'Foo' ,
2268
+ age : 12
2269
+ } ;
2270
+ } ;
2271
+
2272
+ var el = createUiSelectMultiple ( { tagging : 'taggingFunc' , groupBy : "'age'" } ) ;
2273
+
2274
+ showChoicesForSearch ( el , 'amal' ) ;
2275
+ expect ( el . find ( '.ui-select-choices-row-inner' ) . size ( ) ) . toBe ( 2 ) ;
2276
+ expect ( el . scope ( ) . $select . items [ 0 ] ) . toEqual ( jasmine . objectContaining ( { name : 'amal' , email : 'amal@email.com' , isTag : true } ) ) ;
2277
+ expect ( el . scope ( ) . $select . items [ 1 ] ) . toEqual ( jasmine . objectContaining ( { name : 'Amalie' , email : 'amalie@email.com' } ) ) ;
2278
+ } ) ;
2279
+
2209
2280
it ( 'should allow paste tag from clipboard' , function ( ) {
2210
2281
scope . taggingFunc = function ( name ) {
2211
2282
return {
0 commit comments