@@ -15,6 +15,11 @@ const QUESTION_CONFIG = {
15
15
messages : MESSAGES ,
16
16
} ;
17
17
18
+ const caseFn = ( input : string | string [ ] , delimiter ?: string ) =>
19
+ ( Array . isArray ( input ) ? input : [ input ] )
20
+ . map ( ( segment ) => segment [ 0 ] . toUpperCase ( ) + segment . slice ( 1 ) )
21
+ . join ( delimiter ) ;
22
+
18
23
describe ( 'name' , ( ) => {
19
24
test ( 'should throw error when name is not a meaningful string' , ( ) => {
20
25
expect (
@@ -47,7 +52,7 @@ describe('name', () => {
47
52
} ) ;
48
53
49
54
describe ( 'type' , ( ) => {
50
- test ( 'should return "list" type when enumList is array' , ( ) => {
55
+ test ( 'should return "list" type when enumList is array and multipleSelectDefaultDelimiter is undefined ' , ( ) => {
51
56
const question = new Question ( 'scope' , {
52
57
...QUESTION_CONFIG ,
53
58
enumList : [ 'cli' , 'core' ] ,
@@ -57,6 +62,17 @@ describe('type', () => {
57
62
expect ( question ) . not . toHaveProperty ( 'transformer' ) ;
58
63
} ) ;
59
64
65
+ test ( 'should return "checkbox" type when enumList is array and multipleSelectDefaultDelimiter is defined' , ( ) => {
66
+ const question = new Question ( 'scope' , {
67
+ ...QUESTION_CONFIG ,
68
+ enumList : [ 'cli' , 'core' ] ,
69
+ multipleSelectDefaultDelimiter : ',' ,
70
+ } ) . question ;
71
+ expect ( question ) . toHaveProperty ( 'type' , 'checkbox' ) ;
72
+ expect ( question ) . toHaveProperty ( 'choices' , [ 'cli' , 'core' ] ) ;
73
+ expect ( question ) . not . toHaveProperty ( 'transformer' ) ;
74
+ } ) ;
75
+
60
76
test ( 'should contain "skip" list item when enumList is array and skip is true' , ( ) => {
61
77
const question = new Question ( 'scope' , {
62
78
...QUESTION_CONFIG ,
@@ -184,13 +200,46 @@ describe('filter', () => {
184
200
test ( 'should auto fix case and full-stop' , ( ) => {
185
201
const question = new Question ( 'body' , {
186
202
...QUESTION_CONFIG ,
187
- caseFn : ( input : string ) => input [ 0 ] . toUpperCase ( ) + input . slice ( 1 ) ,
203
+ caseFn,
188
204
fullStopFn : ( input : string ) => input + '!' ,
189
205
} ) . question ;
190
206
191
207
expect ( question . filter ?.( 'xxxx' , { } ) ) . toBe ( 'Xxxx!' ) ;
192
208
} ) ;
193
209
210
+ test ( 'should transform each item with same case when input is array' , ( ) => {
211
+ const question = new Question ( 'body' , {
212
+ ...QUESTION_CONFIG ,
213
+ caseFn,
214
+ fullStopFn : ( input : string ) => input + '!' ,
215
+ } ) . question ;
216
+
217
+ expect ( question . filter ?.( [ 'xxxx' , 'yyyy' ] , { } ) ) . toBe ( 'Xxxx,Yyyy!' ) ;
218
+ } ) ;
219
+
220
+ test ( 'should concat items with multipleSelectDefaultDelimiter when input is array' , ( ) => {
221
+ const question = new Question ( 'body' , {
222
+ ...QUESTION_CONFIG ,
223
+ caseFn,
224
+ fullStopFn : ( input : string ) => input + '!' ,
225
+ multipleSelectDefaultDelimiter : '|' ,
226
+ } ) . question ;
227
+
228
+ expect ( question . filter ?.( [ 'xxxx' , 'yyyy' ] , { } ) ) . toBe ( 'Xxxx|Yyyy!' ) ;
229
+ } ) ;
230
+
231
+ test ( 'should split the string to items when multipleValueDelimiters is defined' , ( ) => {
232
+ const question = new Question ( 'body' , {
233
+ ...QUESTION_CONFIG ,
234
+ caseFn,
235
+ fullStopFn : ( input : string ) => input + '!' ,
236
+ multipleValueDelimiters : / , | \| / g,
237
+ } ) . question ;
238
+
239
+ expect ( question . filter ?.( 'xxxx,yyyy|zzzz' , { } ) ) . toBe ( 'Xxxx,Yyyy|Zzzz!' ) ;
240
+ expect ( question . filter ?.( 'xxxx-yyyy-zzzz' , { } ) ) . toBe ( 'Xxxx-yyyy-zzzz!' ) ;
241
+ } ) ;
242
+
194
243
test ( 'should works well when does not pass caseFn/fullStopFn' , ( ) => {
195
244
const question = new Question ( 'body' , {
196
245
...QUESTION_CONFIG ,
@@ -252,7 +301,7 @@ describe('transformer', () => {
252
301
test ( 'should auto transform case and full-stop' , ( ) => {
253
302
const question = new Question ( 'body' , {
254
303
...QUESTION_CONFIG ,
255
- caseFn : ( input : string ) => input [ 0 ] . toUpperCase ( ) + input . slice ( 1 ) ,
304
+ caseFn,
256
305
fullStopFn : ( input : string ) => input + '!' ,
257
306
} ) . question ;
258
307
0 commit comments