@@ -60,6 +60,22 @@ describe('ui-select tests', function() {
6060 return person . age % 2 ? 'even' : 'odd' ;
6161 } ;
6262
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+
6379 scope . people = [
6480 { name : 'Adam' , email : 'adam@email.com' , group : 'Foo' , age : 12 } ,
6581 { name : 'Amalie' , email : 'amalie@email.com' , group : 'Foo' , age : 12 } ,
@@ -683,25 +699,48 @@ describe('ui-select tests', function() {
683699 } ) ;
684700 } ) ;
685701
686- describe ( 'choices group by function' , function ( ) {
702+ describe ( 'choices group filter function' , function ( ) {
687703 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>'
695711 ) ;
696712 }
697- it ( "should extract group value through function " , function ( ) {
713+ it ( "should sort groups using filter " , function ( ) {
698714 var el = createUiSelect ( ) ;
715+ debugger ;
699716 expect ( el . find ( '.ui-select-choices-group .ui-select-choices-group-label' ) . map ( function ( ) {
700717 return this . textContent ;
701- } ) . toArray ( ) ) . toEqual ( [ 'odd' , 'even' ] ) ;
718+ } ) . toArray ( ) ) . toEqual ( [ "Foo" , "Baz" , "bar" ] ) ;
702719 } ) ;
703720 } ) ;
704721
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+
705744 it ( 'should throw when no ui-select-choices found' , function ( ) {
706745 expect ( function ( ) {
707746 compileTemplate (
0 commit comments