@@ -460,29 +460,54 @@ describe('ui-select tests', function() {
460
460
461
461
it ( 'should invoke select callback on select' , function ( ) {
462
462
463
- scope . onSelectFn = function ( $item , $model , $label ) {
464
- scope . $item = $item ;
465
- scope . $model = $model ;
466
- } ;
467
- var el = compileTemplate (
468
- '<ui-select on-select="onSelectFn($item, $model)" ng-model="selection.selected"> \
469
- <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
470
- <ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
471
- <div ng-bind-html="person.name | highlight: $select.search"></div> \
472
- <div ng-bind-html="person.email | highlight: $select.search"></div> \
473
- </ui-select-choices> \
474
- </ui-select>'
475
- ) ;
463
+ scope . onSelectFn = function ( $item , $model , $label ) {
464
+ scope . $item = $item ;
465
+ scope . $model = $model ;
466
+ } ;
467
+ var el = compileTemplate (
468
+ '<ui-select on-select="onSelectFn($item, $model)" ng-model="selection.selected"> \
469
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
470
+ <ui-select-choices repeat="person.name as person in people | filter: $select.search"> \
471
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
472
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
473
+ </ui-select-choices> \
474
+ </ui-select>'
475
+ ) ;
476
+
477
+ expect ( scope . $item ) . toBeFalsy ( ) ;
478
+ expect ( scope . $model ) . toBeFalsy ( ) ;
476
479
477
- expect ( scope . $item ) . toBeFalsy ( ) ;
478
- expect ( scope . $model ) . toBeFalsy ( ) ;
480
+ clickItem ( el , 'Samantha' ) ;
481
+ expect ( scope . selection . selected ) . toBe ( 'Samantha' ) ;
479
482
480
- clickItem ( el , 'Samantha' ) ;
481
- expect ( scope . selection . selected ) . toBe ( 'Samantha' ) ;
483
+ expect ( scope . $item ) . toEqual ( scope . people [ 5 ] ) ;
484
+ expect ( scope . $model ) . toEqual ( 'Samantha' ) ;
482
485
483
- expect ( scope . $item ) . toEqual ( scope . people [ 5 ] ) ;
484
- expect ( scope . $model ) . toEqual ( 'Samantha' ) ;
486
+ } ) ;
485
487
486
- } ) ;
488
+ it ( 'should set $item & $model correctly when invoking callback on select and no single prop. binding' , function ( ) {
489
+
490
+ scope . onSelectFn = function ( $item , $model , $label ) {
491
+ scope . $item = $item ;
492
+ scope . $model = $model ;
493
+ } ;
494
+
495
+ var el = compileTemplate (
496
+ '<ui-select on-select="onSelectFn($item, $model)" ng-model="selection.selected"> \
497
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
498
+ <ui-select-choices repeat="person in people | filter: $select.search"> \
499
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
500
+ <div ng-bind-html="person.email | highlight: $select.search"></div> \
501
+ </ui-select-choices> \
502
+ </ui-select>'
503
+ ) ;
504
+
505
+ expect ( scope . $item ) . toBeFalsy ( ) ;
506
+ expect ( scope . $model ) . toBeFalsy ( ) ;
507
+
508
+ clickItem ( el , 'Samantha' ) ;
509
+ expect ( scope . $item ) . toEqual ( scope . $model ) ;
510
+
511
+ } ) ;
487
512
488
513
} ) ;
0 commit comments