@@ -130,5 +130,84 @@ describe('MultiSelectPrompt', () => {
130
130
input . emit ( 'keypress' , 'i' , { name : 'i' } ) ;
131
131
expect ( instance . value ) . toEqual ( [ 'foo' ] ) ;
132
132
} ) ;
133
+
134
+ test ( 'disabled options are skipped' , ( ) => {
135
+ const instance = new MultiSelectPrompt ( {
136
+ input,
137
+ output,
138
+ render : ( ) => 'foo' ,
139
+ options : [ { value : 'foo' } , { value : 'bar' , disabled : true } , { value : 'baz' } ] ,
140
+ } ) ;
141
+ instance . prompt ( ) ;
142
+
143
+ expect ( instance . cursor ) . to . equal ( 0 ) ;
144
+ input . emit ( 'keypress' , 'down' , { name : 'down' } ) ;
145
+ expect ( instance . cursor ) . to . equal ( 2 ) ;
146
+ input . emit ( 'keypress' , 'up' , { name : 'up' } ) ;
147
+ expect ( instance . cursor ) . to . equal ( 0 ) ;
148
+ } ) ;
149
+
150
+ test ( 'initial cursorAt on disabled option' , ( ) => {
151
+ const instance = new MultiSelectPrompt ( {
152
+ input,
153
+ output,
154
+ render : ( ) => 'foo' ,
155
+ options : [ { value : 'foo' } , { value : 'bar' , disabled : true } , { value : 'baz' } ] ,
156
+ cursorAt : 'bar' ,
157
+ } ) ;
158
+ instance . prompt ( ) ;
159
+
160
+ expect ( instance . cursor ) . to . equal ( 2 ) ;
161
+ } ) ;
162
+ } ) ;
163
+
164
+ describe ( 'toggleAll' , ( ) => {
165
+ test ( 'selects all enabled options' , ( ) => {
166
+ const instance = new MultiSelectPrompt ( {
167
+ input,
168
+ output,
169
+ render : ( ) => 'foo' ,
170
+ options : [ { value : 'foo' } , { value : 'bar' , disabled : true } , { value : 'baz' } ] ,
171
+ } ) ;
172
+ instance . prompt ( ) ;
173
+
174
+ input . emit ( 'keypress' , 'a' , { name : 'a' } ) ;
175
+ expect ( instance . value ) . toEqual ( [ 'foo' , 'baz' ] ) ;
176
+ } ) ;
177
+
178
+ test ( 'unselects all enabled options if all selected' , ( ) => {
179
+ const instance = new MultiSelectPrompt ( {
180
+ input,
181
+ output,
182
+ render : ( ) => 'foo' ,
183
+ options : [ { value : 'foo' } , { value : 'bar' , disabled : true } , { value : 'baz' } ] ,
184
+ initialValues : [ 'foo' , 'baz' ] ,
185
+ } ) ;
186
+ instance . prompt ( ) ;
187
+
188
+ input . emit ( 'keypress' , 'a' , { name : 'a' } ) ;
189
+ expect ( instance . value ) . toEqual ( [ ] ) ;
190
+ } ) ;
191
+ } ) ;
192
+
193
+ describe ( 'toggleInvert' , ( ) => {
194
+ test ( 'inverts selection of enabled options' , ( ) => {
195
+ const instance = new MultiSelectPrompt ( {
196
+ input,
197
+ output,
198
+ render : ( ) => 'foo' ,
199
+ options : [
200
+ { value : 'foo' } ,
201
+ { value : 'bar' , disabled : true } ,
202
+ { value : 'baz' } ,
203
+ { value : 'qux' } ,
204
+ ] ,
205
+ initialValues : [ 'foo' , 'baz' ] ,
206
+ } ) ;
207
+ instance . prompt ( ) ;
208
+
209
+ input . emit ( 'keypress' , 'i' , { name : 'i' } ) ;
210
+ expect ( instance . value ) . toEqual ( [ 'qux' ] ) ;
211
+ } ) ;
133
212
} ) ;
134
213
} ) ;
0 commit comments