1
1
'use strict' ;
2
2
3
3
describe ( 'ui-select tests' , function ( ) {
4
- var scope , $rootScope , $compile , $timeout , $injector , uisRepeatParser ;
4
+ var scope , $rootScope , $compile , $timeout , $injector , $q , uisRepeatParser ;
5
5
6
6
var Key = {
7
7
Enter : 13 ,
@@ -78,12 +78,13 @@ describe('ui-select tests', function() {
78
78
} ) ;
79
79
} ) ;
80
80
81
- beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$timeout_ , _$injector_ , _uisRepeatParser_ ) {
81
+ beforeEach ( inject ( function ( _$rootScope_ , _$compile_ , _$timeout_ , _$injector_ , _$q_ , _uisRepeatParser_ ) {
82
82
$rootScope = _$rootScope_ ;
83
83
scope = $rootScope . $new ( ) ;
84
84
$compile = _$compile_ ;
85
85
$timeout = _$timeout_ ;
86
86
$injector = _$injector_ ;
87
+ $q = _$q_ ;
87
88
uisRepeatParser = _uisRepeatParser_ ;
88
89
scope . selection = { } ;
89
90
@@ -146,7 +147,8 @@ describe('ui-select tests', function() {
146
147
147
148
function createUiSelect ( attrs ) {
148
149
var attrsHtml = '' ,
149
- matchAttrsHtml = '' ;
150
+ matchAttrsHtml = '' ,
151
+ choicesAttrsHtml = ''
150
152
if ( attrs !== undefined ) {
151
153
if ( attrs . disabled !== undefined ) { attrsHtml += ' ng-disabled="' + attrs . disabled + '"' ; }
152
154
if ( attrs . required !== undefined ) { attrsHtml += ' ng-required="' + attrs . required + '"' ; }
@@ -161,12 +163,16 @@ describe('ui-select tests', function() {
161
163
if ( attrs . ngClass !== undefined ) { attrsHtml += ' ng-class="' + attrs . ngClass + '"' ; }
162
164
if ( attrs . resetSearchInput !== undefined ) { attrsHtml += ' reset-search-input="' + attrs . resetSearchInput + '"' ; }
163
165
if ( attrs . closeOnSelect !== undefined ) { attrsHtml += ' close-on-select="' + attrs . closeOnSelect + '"' ; }
166
+ if ( attrs . spinnerEnabled !== undefined ) { attrsHtml += ' spinner-enabled="' + attrs . spinnerEnabled + '"' ; }
167
+ if ( attrs . spinnerClass !== undefined ) { attrsHtml += ' spinner-class="' + attrs . spinnerClass + '"' ; }
168
+ if ( attrs . refresh !== undefined ) { choicesAttrsHtml += ' refresh="' + attrs . refresh + '"' ; }
169
+ if ( attrs . refreshDelay !== undefined ) { choicesAttrsHtml += ' refresh-delay="' + attrs . refreshDelay + '"' ; }
164
170
}
165
171
166
172
return compileTemplate (
167
173
'<ui-select ng-model="selection.selected"' + attrsHtml + '> \
168
174
<ui-select-match placeholder="Pick one..."' + matchAttrsHtml + '>{{$select.selected.name}}</ui-select-match> \
169
- <ui-select-choices repeat="person in people | filter: $select.search"> \
175
+ <ui-select-choices repeat="person in people | filter: $select.search"' + choicesAttrsHtml + '" > \
170
176
<div ng-bind-html="person.name | highlight: $select.search"></div> \
171
177
<div ng-bind-html="person.email | highlight: $select.search"></div> \
172
178
</ui-select-choices> \
@@ -3031,4 +3037,66 @@ describe('ui-select tests', function() {
3031
3037
} ) ;
3032
3038
} ) ;
3033
3039
3040
+ describe ( 'Test Spinner for promises' , function ( ) {
3041
+ var deferred ;
3042
+
3043
+ function getFromServer ( ) {
3044
+ deferred = $q . defer ( ) ;
3045
+ return deferred . promise ;
3046
+ }
3047
+ it ( 'should have a default value of false' , function ( ) {
3048
+ var control = createUiSelect ( ) ;
3049
+ expect ( control . scope ( ) . $select . spinnerEnabled ) . toEqual ( false ) ;
3050
+ } ) ;
3051
+
3052
+ it ( 'should have a set a value of true' , function ( ) {
3053
+ var control = createUiSelect ( { spinnerEnabled : true } ) ;
3054
+ expect ( control . scope ( ) . $select . spinnerEnabled ) . toEqual ( true ) ;
3055
+ } ) ;
3056
+
3057
+ it ( 'should have a default value of glyphicon-refresh ui-select-spin' , function ( ) {
3058
+ var control = createUiSelect ( ) ;
3059
+ expect ( control . scope ( ) . $select . spinnerClass ) . toEqual ( 'glyphicon-refresh ui-select-spin' ) ;
3060
+ } ) ;
3061
+
3062
+ it ( 'should have set a custom class value of randomclass' , function ( ) {
3063
+ var control = createUiSelect ( { spinnerClass : 'randomclass' } ) ;
3064
+ expect ( control . scope ( ) . $select . spinnerClass ) . toEqual ( 'randomclass' ) ;
3065
+ } ) ;
3066
+
3067
+ it ( 'should not display spinner when disabled' , function ( ) {
3068
+ scope . getFromServer = getFromServer ;
3069
+ var el = createUiSelect ( { theme : 'bootstrap' , refresh :"getFromServer($select.search)" , refreshDelay :0 } ) ;
3070
+ openDropdown ( el ) ;
3071
+ var spinner = el . find ( '.ui-select-refreshing' ) ;
3072
+ expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
3073
+ setSearchText ( el , 'a' ) ;
3074
+ expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
3075
+ deferred . resolve ( ) ;
3076
+ scope . $digest ( ) ;
3077
+ expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
3078
+ } ) ;
3079
+
3080
+ it ( 'should display spinner when enabled' , function ( ) {
3081
+ scope . getFromServer = getFromServer ;
3082
+ var el = createUiSelect ( { spinnerEnabled : true , theme : 'bootstrap' , refresh :"getFromServer($select.search)" , refreshDelay :0 } ) ;
3083
+ openDropdown ( el ) ;
3084
+ var spinner = el . find ( '.ui-select-refreshing' ) ;
3085
+ expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
3086
+ setSearchText ( el , 'a' ) ;
3087
+ expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( false ) ;
3088
+ deferred . resolve ( ) ;
3089
+ scope . $digest ( ) ;
3090
+ expect ( spinner . hasClass ( 'ng-hide' ) ) . toBe ( true ) ;
3091
+ } ) ;
3092
+
3093
+ it ( 'should not display spinner when enabled' , function ( ) {
3094
+ var el = createUiSelect ( { spinnerEnabled : true , theme : 'bootstrap' , spinnerClass : 'randomclass' } ) ;
3095
+ openDropdown ( el ) ;
3096
+ var spinner = el . find ( '.ui-select-refreshing' ) ;
3097
+ setSearchText ( el , 'a' ) ;
3098
+ expect ( el . scope ( ) . $select . spinnerClass ) . toBe ( 'randomclass' ) ;
3099
+ } ) ;
3100
+ } ) ;
3101
+
3034
3102
} ) ;
0 commit comments