@@ -15,6 +15,11 @@ const QUESTION_CONFIG = {
1515 messages : MESSAGES ,
1616} ;
1717
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+
1823describe ( 'name' , ( ) => {
1924 test ( 'should throw error when name is not a meaningful string' , ( ) => {
2025 expect (
@@ -47,7 +52,7 @@ describe('name', () => {
4752} ) ;
4853
4954describe ( '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 ' , ( ) => {
5156 const question = new Question ( 'scope' , {
5257 ...QUESTION_CONFIG ,
5358 enumList : [ 'cli' , 'core' ] ,
@@ -57,6 +62,17 @@ describe('type', () => {
5762 expect ( question ) . not . toHaveProperty ( 'transformer' ) ;
5863 } ) ;
5964
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+
6076 test ( 'should contain "skip" list item when enumList is array and skip is true' , ( ) => {
6177 const question = new Question ( 'scope' , {
6278 ...QUESTION_CONFIG ,
@@ -184,13 +200,46 @@ describe('filter', () => {
184200 test ( 'should auto fix case and full-stop' , ( ) => {
185201 const question = new Question ( 'body' , {
186202 ...QUESTION_CONFIG ,
187- caseFn : ( input : string ) => input [ 0 ] . toUpperCase ( ) + input . slice ( 1 ) ,
203+ caseFn,
188204 fullStopFn : ( input : string ) => input + '!' ,
189205 } ) . question ;
190206
191207 expect ( question . filter ?.( 'xxxx' , { } ) ) . toBe ( 'Xxxx!' ) ;
192208 } ) ;
193209
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+
194243 test ( 'should works well when does not pass caseFn/fullStopFn' , ( ) => {
195244 const question = new Question ( 'body' , {
196245 ...QUESTION_CONFIG ,
@@ -252,7 +301,7 @@ describe('transformer', () => {
252301 test ( 'should auto transform case and full-stop' , ( ) => {
253302 const question = new Question ( 'body' , {
254303 ...QUESTION_CONFIG ,
255- caseFn : ( input : string ) => input [ 0 ] . toUpperCase ( ) + input . slice ( 1 ) ,
304+ caseFn,
256305 fullStopFn : ( input : string ) => input + '!' ,
257306 } ) . question ;
258307
0 commit comments