@@ -82,4 +82,74 @@ describe("Select Plugin", function () {
82
82
} ) ;
83
83
84
84
} ) ;
85
+
86
+ describe ( "Optgroup Select" , function ( ) {
87
+ var browserSelect , optInput , optDropdown ;
88
+
89
+ beforeEach ( function ( ) {
90
+ browserSelect = $ ( 'select.optgroup' ) ;
91
+ } ) ;
92
+
93
+ it ( "should open dropdown and select options" , function ( done ) {
94
+ optInput = browserSelect . parent ( ) . find ( 'input.select-dropdown' ) ;
95
+ optDropdown = browserSelect . parent ( ) . find ( 'ul.select-dropdown' ) ;
96
+
97
+ var optgroups = optDropdown . find ( 'li.optgroup' ) ;
98
+ browserSelect . find ( 'optgroup' ) . each ( function ( i ) {
99
+ expect ( $ ( this ) . attr ( 'label' ) ) . toEqual ( optgroups . eq ( i ) [ 0 ] . innerText , 'should generate optgroup structure.' ) ;
100
+ } ) ;
101
+
102
+ expect ( optInput ) . toExist ( 'Should dynamically generate select dropdown structure.' ) ;
103
+ expect ( optDropdown ) . toExist ( 'Should dynamically generate select dropdown structure.' ) ;
104
+ expect ( optInput ) . toBeVisible ( 'Should be hidden before dropdown is opened.' ) ;
105
+ expect ( optDropdown ) . toBeHidden ( 'Should be hidden before dropdown is opened.' ) ;
106
+
107
+ optInput . click ( ) ;
108
+
109
+ setTimeout ( function ( ) {
110
+ expect ( optDropdown ) . toBeVisible ( 'Should be visible after opening.' ) ;
111
+ var secondOption = optDropdown . find ( 'li:not(.disabled):not(.optgroup)' ) . eq ( 1 ) ;
112
+ secondOption . click ( ) ;
113
+ optInput . blur ( ) ;
114
+
115
+ setTimeout ( function ( ) {
116
+ expect ( optDropdown ) . toBeHidden ( 'Should be hidden after choosing item.' ) ;
117
+ expect ( optInput . val ( ) ) . toEqual ( secondOption [ 0 ] . innerText , 'Value should be equal to selected option.' ) ;
118
+ done ( ) ;
119
+ } , 400 ) ;
120
+ } , 400 ) ;
121
+ } ) ;
122
+
123
+ it ( "should not do anything when optgroup li clicked" , function ( done ) {
124
+ optInput = browserSelect . parent ( ) . find ( 'input.select-dropdown' ) ;
125
+ optDropdown = browserSelect . parent ( ) . find ( 'ul.select-dropdown' ) ;
126
+ var originalVal = optInput . val ( ) ;
127
+
128
+ var optgroups = optDropdown . find ( 'li.optgroup' ) ;
129
+ browserSelect . find ( 'optgroup' ) . each ( function ( i ) {
130
+ expect ( $ ( this ) . attr ( 'label' ) ) . toEqual ( optgroups . eq ( i ) [ 0 ] . innerText , 'should generate optgroup structure.' ) ;
131
+ } ) ;
132
+
133
+ expect ( optInput ) . toExist ( 'Should dynamically generate select dropdown structure.' ) ;
134
+ expect ( optDropdown ) . toExist ( 'Should dynamically generate select dropdown structure.' ) ;
135
+ expect ( optInput ) . toBeVisible ( 'Should be hidden before dropdown is opened.' ) ;
136
+ expect ( optDropdown ) . toBeHidden ( 'Should be hidden before dropdown is opened.' ) ;
137
+
138
+ optInput . click ( ) ;
139
+
140
+ setTimeout ( function ( ) {
141
+ expect ( optDropdown ) . toBeVisible ( 'Should be visible after opening.' ) ;
142
+ var optgroup = optDropdown . find ( 'li.optgroup' ) . first ( ) ;
143
+ optgroup . click ( ) ;
144
+ optInput . blur ( ) ;
145
+
146
+ setTimeout ( function ( ) {
147
+ expect ( optDropdown ) . toBeHidden ( 'Should be hidden after choosing invalid item.' ) ;
148
+ expect ( optInput . val ( ) ) . toEqual ( originalVal , 'Value should be equal to original option.' ) ;
149
+ done ( ) ;
150
+ } , 400 ) ;
151
+ } , 400 ) ;
152
+ } ) ;
153
+
154
+ } ) ;
85
155
} ) ;
0 commit comments