@@ -73,4 +73,67 @@ describe('features about live search related, etc;', function() {
7373 check ( ) ;
7474 } ) ;
7575
76+ it ( 'should clear live-search' , function ( ) {
77+ // get amount of available li
78+ function get_amount ( ) {
79+ var list = selectElement . find ( 'ul' ) . children ( ) ;
80+ var i , k , length = list . length ,
81+ liElement ,
82+ classList ,
83+ check ,
84+ counter = 0 ;
85+ for ( i = 0 ; i < length ; i ++ ) {
86+ liElement = list . eq ( i ) ;
87+ if ( liElement . hasClass ( 'nya-bs-option' ) ) {
88+ classList = liElement [ 0 ] . classList ;
89+ check = false ;
90+ for ( k = 0 ; k < classList . length ; k ++ ) {
91+ if ( classList [ k ] === 'not-match' ) {
92+ check = true ;
93+ }
94+ }
95+ if ( check === false ) {
96+ counter ++ ;
97+ }
98+ }
99+ }
100+ return counter ;
101+ }
102+
103+ // string array
104+ $scope . options = options ;
105+ $scope . model = [ ] ;
106+ $scope . $digest ( ) ;
107+ var selectElement = angular . element ( '<ol class="nya-bs-select" ng-model="model" live-search="true">' +
108+ '<li nya-bs-option="option in options">' +
109+ '<a>{{option}}</a>' +
110+ '</li>' +
111+ '</ol>' ) ;
112+ $compile ( selectElement ) ( $scope ) ;
113+
114+ $scope . $digest ( ) ;
115+ //open dropdown
116+ selectElement . find ( 'button' ) [ 0 ] . click ( ) ;
117+ //get amount of options
118+ var before_change = get_amount ( selectElement , 'amount' ) ;
119+ //set live-search
120+ selectElement . find ( 'input' ) . val ( 'o' ) ;
121+ //trigger live-search
122+ selectElement . find ( 'input' ) . triggerHandler ( 'input' ) ;
123+ //trigger digest cycle
124+ $scope . $digest ( ) ;
125+ //check if value is set
126+ expect ( selectElement . find ( 'input' ) . val ( ) ) . toBe ( 'o' ) ;
127+ //check amount of options vs new amount
128+ expect ( get_amount ( selectElement , 'amount' ) ) . not . toBe ( before_change ) ;
129+ //close dropdown
130+ selectElement . find ( 'button' ) [ 0 ] . click ( ) ;
131+ //open dropdown
132+ selectElement . find ( 'button' ) [ 0 ] . click ( ) ;
133+ //check if value is empty
134+ expect ( selectElement . find ( 'input' ) . val ( ) ) . toBe ( '' ) ;
135+ //check amount of options vs new amount
136+ expect ( get_amount ( selectElement , 'amount' ) ) . toBe ( before_change ) ;
137+ } ) ;
138+
76139} ) ;
0 commit comments