@@ -109,6 +109,12 @@ describe('ui-select tests', function() {
109
109
element . trigger ( e ) ;
110
110
}
111
111
112
+ function setSearchText ( el , text ) {
113
+ el . scope ( ) . $select . search = text ;
114
+ scope . $digest ( ) ;
115
+ $timeout . flush ( ) ;
116
+ }
117
+
112
118
// Tests
113
119
114
120
it ( 'should compile child directives' , function ( ) {
@@ -558,7 +564,7 @@ describe('ui-select tests', function() {
558
564
<div ng-bind-html="person.name | highlight: $select.search"></div> \
559
565
<div ng-if="person.name==\'Wladimir\'"> \
560
566
<span class="only-once">I should appear only once</span>\
561
- ® </div> \
567
+ </div> \
562
568
</ui-select-choices> \
563
569
</ui-select>'
564
570
) ;
@@ -568,6 +574,97 @@ describe('ui-select tests', function() {
568
574
569
575
} ) ;
570
576
577
+ it ( 'should call refresh function when search text changes' , function ( ) {
578
+
579
+ var el = compileTemplate (
580
+ '<ui-select ng-model="selection.selected"> \
581
+ <ui-select-match> \
582
+ </ui-select-match> \
583
+ <ui-select-choices repeat="person in people | filter: $select.search" \
584
+ refresh="fetchFromServer($select.search)" refresh-delay="0"> \
585
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
586
+ <div ng-if="person.name==\'Wladimir\'"> \
587
+ <span class="only-once">I should appear only once</span>\
588
+ </div> \
589
+ </ui-select-choices> \
590
+ </ui-select>'
591
+ ) ;
592
+
593
+ scope . fetchFromServer = function ( ) { } ;
594
+
595
+ spyOn ( scope , 'fetchFromServer' ) ;
596
+
597
+ el . scope ( ) . $select . search = 'r' ;
598
+ scope . $digest ( ) ;
599
+ $timeout . flush ( ) ;
600
+
601
+ expect ( scope . fetchFromServer ) . toHaveBeenCalledWith ( 'r' ) ;
602
+
603
+ } ) ;
604
+
605
+ it ( 'should call refresh function when search text changes' , function ( ) {
606
+
607
+ var el = compileTemplate (
608
+ '<ui-select ng-model="selection.selected"> \
609
+ <ui-select-match> \
610
+ </ui-select-match> \
611
+ <ui-select-choices repeat="person in people | filter: $select.search" \
612
+ refresh="fetchFromServer($select.search)" refresh-delay="0"> \
613
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
614
+ <div ng-if="person.name==\'Wladimir\'"> \
615
+ <span class="only-once">I should appear only once</span>\
616
+ </div> \
617
+ </ui-select-choices> \
618
+ </ui-select>'
619
+ ) ;
620
+
621
+ scope . fetchFromServer = function ( ) { } ;
622
+
623
+ spyOn ( scope , 'fetchFromServer' ) ;
624
+
625
+ el . scope ( ) . $select . search = 'r' ;
626
+ scope . $digest ( ) ;
627
+ $timeout . flush ( ) ;
628
+
629
+ expect ( scope . fetchFromServer ) . toHaveBeenCalledWith ( 'r' ) ;
630
+
631
+ } ) ;
632
+
633
+ it ( 'should format view value correctly when using single property binding and refresh funcion' , function ( ) {
634
+
635
+ var el = compileTemplate (
636
+ '<ui-select ng-model="selection.selected"> \
637
+ <ui-select-match>{{$select.selected.name}}</ui-select-match> \
638
+ <ui-select-choices repeat="person.name as person in people | filter: $select.search" \
639
+ refresh="fetchFromServer($select.search)" refresh-delay="0"> \
640
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
641
+ <div ng-if="person.name==\'Wladimir\'"> \
642
+ <span class="only-once">I should appear only once</span>\
643
+ </div> \
644
+ </ui-select-choices> \
645
+ </ui-select>'
646
+ ) ;
647
+
648
+ scope . fetchFromServer = function ( searching ) {
649
+
650
+ if ( searching == 's' )
651
+ return scope . people
652
+
653
+ if ( searching == 'o' ) {
654
+ scope . people = [ ] ; //To simulate cases were previously selected item isnt in the list anymore
655
+ }
656
+
657
+ } ;
658
+
659
+ setSearchText ( el , 'r' )
660
+ clickItem ( el , 'Samantha' ) ;
661
+ expect ( getMatchLabel ( el ) ) . toBe ( 'Samantha' ) ;
662
+
663
+ setSearchText ( el , 'o' )
664
+ expect ( getMatchLabel ( el ) ) . toBe ( 'Samantha' ) ;
665
+
666
+ } ) ;
667
+
571
668
describe ( 'search-enabled option' , function ( ) {
572
669
573
670
var el ;
0 commit comments