@@ -60,6 +60,22 @@ describe('ui-select tests', function() {
60
60
return person . age % 2 ? 'even' : 'odd' ;
61
61
} ;
62
62
63
+
64
+ scope . filterInvertOrder = function ( groups ) {
65
+ debugger ;
66
+ var results = groups . sort ( function ( groupA , groupB ) {
67
+ return groupA . name . toLocaleLowerCase ( ) < groupB . name . toLocaleLowerCase ( ) ;
68
+ } ) ;
69
+ return results ;
70
+ } ;
71
+
72
+ scope . filterBarAndBaz = function ( groups ) {
73
+ debugger ;
74
+ return groups . sort ( function ( groupA , groupB ) {
75
+ return groupA . name . toLocaleLowerCase ( ) < groupB . name . toLocaleLowerCase ( ) ;
76
+ } ) ;
77
+ } ;
78
+
63
79
scope . people = [
64
80
{ name : 'Adam' , email : 'adam@email.com' , group : 'Foo' , age : 12 } ,
65
81
{ name : 'Amalie' , email : 'amalie@email.com' , group : 'Foo' , age : 12 } ,
@@ -683,25 +699,48 @@ describe('ui-select tests', function() {
683
699
} ) ;
684
700
} ) ;
685
701
686
- describe ( 'choices group by function' , function ( ) {
702
+ describe ( 'choices group filter function' , function ( ) {
687
703
function createUiSelect ( ) {
688
- return compileTemplate (
689
- ' <ui-select ng-model="selection.selected"> \
690
- <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
691
- <ui-select-choices group-by="getGroupLabel" repeat="person in people | filter: $select.search"> \
692
- <div ng-bind-html="person.name | highlight: $select.search"></div> \
693
- </ui-select-choices> \
694
- </ui-select>'
704
+ return compileTemplate ( '\
705
+ <ui-select ng-model="selection.selected"> \
706
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
707
+ <ui-select-choices group-by="\'group\'" group-filter="filterInvertOrder" repeat="person in people | filter: $select.search"> \
708
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
709
+ </ui-select-choices> \
710
+ </ui-select>'
695
711
) ;
696
712
}
697
- it ( "should extract group value through function " , function ( ) {
713
+ it ( "should sort groups using filter " , function ( ) {
698
714
var el = createUiSelect ( ) ;
715
+ debugger ;
699
716
expect ( el . find ( '.ui-select-choices-group .ui-select-choices-group-label' ) . map ( function ( ) {
700
717
return this . textContent ;
701
- } ) . toArray ( ) ) . toEqual ( [ 'odd' , 'even' ] ) ;
718
+ } ) . toArray ( ) ) . toEqual ( [ "Foo" , "Baz" , "bar" ] ) ;
702
719
} ) ;
703
720
} ) ;
704
721
722
+ describe ( 'choices group filter array' , function ( ) {
723
+ function createUiSelect ( ) {
724
+ return compileTemplate ( '\
725
+ <ui-select ng-model="selection.selected"> \
726
+ <ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
727
+ <ui-select-choices group-by="\'group\'" group-filter="[\'Foo\']" \
728
+ repeat="person in people | filter: $select.search"> \
729
+ <div ng-bind-html="person.name | highlight: $select.search"></div> \
730
+ </ui-select-choices> \
731
+ </ui-select>'
732
+ ) ;
733
+ }
734
+ it ( "should sort groups using filter" , function ( ) {
735
+ var el = createUiSelect ( ) ;
736
+ debugger ;
737
+ expect ( el . find ( '.ui-select-choices-group .ui-select-choices-group-label' ) . map ( function ( ) {
738
+ return this . textContent ;
739
+ } ) . toArray ( ) ) . toEqual ( [ "Foo" ] ) ;
740
+ } ) ;
741
+ } ) ;
742
+
743
+
705
744
it ( 'should throw when no ui-select-choices found' , function ( ) {
706
745
expect ( function ( ) {
707
746
compileTemplate (
0 commit comments