@@ -22,7 +22,7 @@ describe('ui-select tests', function() {
22
22
} ) ) ;
23
23
24
24
25
- // Utility functions
25
+ // DSL (domain-specific language)
26
26
27
27
function compileTemplate ( template ) {
28
28
var el = $compile ( angular . element ( template ) ) ( scope ) ;
@@ -53,7 +53,7 @@ describe('ui-select tests', function() {
53
53
}
54
54
55
55
function clickItem ( el , text ) {
56
- $ ( el ) . find ( '.ui-select-choices-row > div:contains("' + text + '")' ) . click ( ) ;
56
+ $ ( el ) . find ( '.ui-select-choices-row div:contains("' + text + '")' ) . click ( ) ;
57
57
scope . $digest ( ) ;
58
58
}
59
59
@@ -62,6 +62,15 @@ describe('ui-select tests', function() {
62
62
scope . $digest ( ) ;
63
63
}
64
64
65
+ function isDropdownOpened ( el ) {
66
+ // Does not work with jQuery 2.*, have to use jQuery 1.11.*
67
+ // This will be fixed in AngularJS 1.3
68
+ // See issue with unit-testing directive using karma https://github.com/angular/angular.js/issues/4640#issuecomment-35002427
69
+ return el . scope ( ) . $select . open && el . hasClass ( 'open' ) ;
70
+ }
71
+
72
+
73
+ // Tests
65
74
66
75
it ( 'should compile child directives' , function ( ) {
67
76
var el = createUiSelect ( ) ;
@@ -78,8 +87,8 @@ describe('ui-select tests', function() {
78
87
var choicesContainerEl = $ ( el ) . find ( '.ui-select-choices' ) ;
79
88
expect ( choicesContainerEl . length ) . toEqual ( 1 ) ;
80
89
81
- var choicesElems = $ ( el ) . find ( '.ui-select-choices-row' ) ;
82
- expect ( choicesElems . length ) . toEqual ( 8 ) ;
90
+ var choicesEls = $ ( el ) . find ( '.ui-select-choices-row' ) ;
91
+ expect ( choicesEls . length ) . toEqual ( 8 ) ;
83
92
} ) ;
84
93
85
94
it ( 'should correctly render initial state' , function ( ) {
@@ -93,15 +102,11 @@ describe('ui-select tests', function() {
93
102
it ( 'should display the choices when activated' , function ( ) {
94
103
var el = createUiSelect ( ) ;
95
104
96
- // Does not work with jQuery 2.*, have to use jQuery 1.11.*
97
- // This will be fixed in AngularJS 1.3
98
- // See issue with unit-testing directive using karma https://github.com/angular/angular.js/issues/4640#issuecomment-35002427
99
- expect ( el . scope ( ) . $select . open ) . toEqual ( false ) ;
105
+ expect ( isDropdownOpened ( el ) ) . toEqual ( false ) ;
100
106
101
107
clickMatch ( el ) ;
102
108
103
- expect ( el . scope ( ) . $select . open ) . toEqual ( true ) ;
104
- expect ( $ ( el ) . find ( '.ui-select-choices' ) . parent ( ) . hasClass ( 'select2-display-none' ) ) . toEqual ( false ) ;
109
+ expect ( isDropdownOpened ( el ) ) . toEqual ( true ) ;
105
110
} ) ;
106
111
107
112
it ( 'should select an item' , function ( ) {
@@ -132,37 +137,35 @@ describe('ui-select tests', function() {
132
137
it ( 'should close the choices when an item is selected' , function ( ) {
133
138
var el = createUiSelect ( ) ;
134
139
135
- $ ( el ) . find ( '.ui-select-match' ) . click ( ) ;
136
- scope . $digest ( ) ;
140
+ clickMatch ( el ) ;
137
141
138
- expect ( el . scope ( ) . $select . open ) . toEqual ( true ) ;
142
+ expect ( isDropdownOpened ( el ) ) . toEqual ( true ) ;
139
143
140
144
clickItem ( el , 'Samantha' ) ;
141
145
142
- expect ( el . scope ( ) . $select . open ) . toEqual ( false ) ;
143
- expect ( $ ( el ) . find ( '.ui-select-choices' ) . parent ( ) . hasClass ( 'select2-display-none' ) ) . toEqual ( true ) ;
146
+ expect ( isDropdownOpened ( el ) ) . toEqual ( false ) ;
144
147
} ) ;
145
148
146
149
it ( 'should be disabled if the attribute says so' , function ( ) {
147
150
var el1 = createUiSelect ( { disabled : true } ) ;
148
151
expect ( el1 . scope ( ) . $select . disabled ) . toEqual ( true ) ;
149
152
clickMatch ( el1 ) ;
150
- expect ( el1 . scope ( ) . $select . open ) . toEqual ( false ) ;
153
+ expect ( isDropdownOpened ( el1 ) ) . toEqual ( false ) ;
151
154
152
155
var el2 = createUiSelect ( { disabled : false } ) ;
153
156
expect ( el2 . scope ( ) . $select . disabled ) . toEqual ( false ) ;
154
157
clickMatch ( el2 ) ;
155
- expect ( el2 . scope ( ) . $select . open ) . toEqual ( true ) ;
158
+ expect ( isDropdownOpened ( el2 ) ) . toEqual ( true ) ;
156
159
157
160
var el3 = createUiSelect ( ) ;
158
161
expect ( el3 . scope ( ) . $select . disabled ) . toEqual ( false ) ;
159
162
clickMatch ( el3 ) ;
160
- expect ( el3 . scope ( ) . $select . open ) . toEqual ( true ) ;
163
+ expect ( isDropdownOpened ( el3 ) ) . toEqual ( true ) ;
161
164
} ) ;
162
165
163
166
// See when an item that evaluates to false (such as "false" or "no") is selected, the placeholder is shown https://github.com/angular-ui/ui-select/pull/32
164
167
it ( 'should not display the placeholder when item evaluates to false' , function ( ) {
165
- scope . items = [ 'false' ] ;
168
+ scope . items = [ 'false' ] ;
166
169
167
170
var el = compileTemplate (
168
171
'<ui-select ng-model="selection"> \
0 commit comments