@@ -2,84 +2,50 @@ import test from 'ava';
22import path from 'path' ;
33import chalk from 'chalk' ;
44import json from 'json-extra' ;
5- import bddStdin from 'bdd-stdin' ;
65import getConfig from '../lib/getConfig' ;
7- import promptConfig from '../lib/promptConfig' ;
6+ import { config , choices , questions } from '../lib/promptConfig' ;
87
98const cwd = process . cwd ( ) ;
109
1110test ( 'get configuration file equals .sgcrc_default' , ( t ) => {
12- const cli = promptConfig ;
13- const config = cli . config ( ) ;
14- t . deepEqual ( config , json . readToObjSync ( path . join ( cwd , '.sgcrc_default' ) ) ) ;
11+ t . deepEqual ( config ( ) , json . readToObjSync ( path . join ( cwd , '.sgcrc_default' ) ) ) ;
1512} ) ;
1613
17- test ( 'choises are the same as choises generated from .sgcrc_default' , ( t ) => {
14+ test ( 'choices are the same as choices generated from .sgcrc_default' , ( t ) => {
1815 const sgc = getConfig ( ) ;
19- const cli = promptConfig ;
20- const config = cli . config ( ) ;
21- const choices = cli . choices ( config ) ;
22- const choicesList = [ ] ;
16+ const configuration = config ( ) ;
17+ const choicesList = choices ( configuration ) ;
18+ const choicesArray = [ ] ;
2319
2420 Promise . resolve ( ( ) => {
2521 sgc . types . forEach ( ( type ) => {
2622 const emoji = `${ type . emoji } ` || '' ;
2723 const configType = type . type ;
2824 const description = type . description || '' ;
2925
30- choicesList . push ( {
26+ choicesArray . push ( {
3127 value : emoji + configType ,
3228 name : `${ chalk . bold ( configType ) } ${ description } ` ,
3329 } ) ;
3430 } ) . then ( ( ) => {
35- t . deepEqual ( choices , choicesList ) ;
31+ t . deepEqual ( choicesList , choicesArray ) ;
3632 } ) ;
3733 } ) ;
3834} ) ;
3935
4036test ( 'check the values of the question object' , ( t ) => {
41- const cli = promptConfig ;
42- const config = cli . config ( ) ;
43- const choices = cli . choices ( config ) ;
44- const questions = cli . questions ( choices ) ;
37+ const configuration = config ( ) ;
38+ const choicesList = choices ( configuration ) ;
39+ const questionsList = questions ( choicesList ) ;
4540
46- t . deepEqual ( questions [ 0 ] . type , 'list' ) ;
47- t . deepEqual ( questions [ 0 ] . name , 'type' ) ;
48- t . deepEqual ( questions [ 0 ] . message , 'Select the type of your commit:' ) ;
49- t . deepEqual ( typeof questions [ 0 ] . choices , 'object' ) ;
50-
51- t . deepEqual ( questions [ 1 ] . type , 'input' ) ;
52- t . deepEqual ( questions [ 1 ] . name , 'description' ) ;
53- t . deepEqual ( questions [ 1 ] . message , 'Enter your commit message:' ) ;
54- t . deepEqual ( typeof questions [ 1 ] . validate , 'function' ) ;
55-
56- t . deepEqual ( questions [ 2 ] . type , 'confirm' ) ;
57- t . deepEqual ( questions [ 2 ] . name , 'moreInfo' ) ;
58- t . deepEqual ( questions [ 2 ] . message , 'Do you want to add more information to your commit?' ) ;
59- t . deepEqual ( questions [ 2 ] . default , false ) ;
60-
61- t . deepEqual ( questions [ 3 ] . type , 'editor' ) ;
62- t . deepEqual ( questions [ 3 ] . name , 'editor' ) ;
63- t . deepEqual ( questions [ 3 ] . message , 'This will let you add more information' ) ;
64- t . deepEqual ( typeof questions [ 3 ] . when , 'function' ) ;
65- t . deepEqual ( typeof questions [ 3 ] . default , 'function' ) ;
41+ t . deepEqual ( typeof questionsList , 'object' ) ;
6642} ) ;
6743
68- test ( 'check cli' , ( t ) => {
69- bddStdin ( bddStdin . keys . down , '\n' ) ;
70- const questions = [
71- {
72- type : 'list' ,
73- name : 'type' ,
74- message : 'Select the type of your commit:' ,
75- choices : [
76- '1' , '2' , '3' ,
77- ] ,
78- } ,
79- ] ;
80- const cli = promptConfig ;
81- return Promise . resolve ( cli . prompt ( questions ) )
82- . then ( ( res ) => {
83- t . deepEqual ( '2' , res ) ;
84- } ) ;
44+ test ( 'validate functions in questions' , ( t ) => {
45+ const configuration = config ( ) ;
46+ const choicesList = choices ( configuration ) ;
47+ const questionsList = questions ( choicesList ) ;
48+
49+ t . deepEqual ( questionsList [ 1 ] . validate ( 'input text' ) , true ) ;
50+ t . deepEqual ( questionsList [ 1 ] . validate ( ) , 'A commit message is mandatory!' ) ;
8551} ) ;
0 commit comments