|
| 1 | +import test from 'ava'; |
| 2 | +import path from 'path'; |
| 3 | +import chalk from 'chalk'; |
| 4 | +import json from 'json-extra'; |
| 5 | +import bddStdin from 'bdd-stdin'; |
| 6 | +import getConfig from '../lib/getConfig'; |
| 7 | +import promptConfig from '../lib/promptConfig'; |
| 8 | + |
| 9 | +const cwd = process.cwd(); |
| 10 | + |
| 11 | +test('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'))); |
| 15 | +}); |
| 16 | + |
| 17 | +test('choises are the same as choises generated from .sgcrc_default', (t) => { |
| 18 | + const sgc = getConfig(); |
| 19 | + const cli = promptConfig; |
| 20 | + const config = cli.config(); |
| 21 | + const choices = cli.choices(config); |
| 22 | + const choicesList = []; |
| 23 | + |
| 24 | + sgc.types.forEach((type) => { |
| 25 | + const emoji = `${type.emoji} ` || ''; |
| 26 | + const configType = type.type; |
| 27 | + const description = type.description || ''; |
| 28 | + |
| 29 | + choicesList.push({ |
| 30 | + value: emoji + configType, |
| 31 | + name: `${chalk.bold(configType)} ${description}`, |
| 32 | + }); |
| 33 | + }); |
| 34 | + t.deepEqual(choices, choicesList); |
| 35 | +}); |
| 36 | + |
| 37 | +test('check the values of the question object', (t) => { |
| 38 | + const cli = promptConfig; |
| 39 | + const config = cli.config(); |
| 40 | + const choices = cli.choices(config); |
| 41 | + const questions = cli.questions(choices); |
| 42 | + |
| 43 | + t.deepEqual(questions[0].type, 'list'); |
| 44 | + t.deepEqual(questions[0].name, 'type'); |
| 45 | + t.deepEqual(questions[0].message, 'Select the type of your commit:'); |
| 46 | + t.deepEqual(typeof questions[0].choices, 'object'); |
| 47 | + |
| 48 | + t.deepEqual(questions[1].type, 'input'); |
| 49 | + t.deepEqual(questions[1].name, 'description'); |
| 50 | + t.deepEqual(questions[1].message, 'Enter your commit message:'); |
| 51 | + t.deepEqual(typeof questions[1].validate, 'function'); |
| 52 | + |
| 53 | + t.deepEqual(questions[2].type, 'confirm'); |
| 54 | + t.deepEqual(questions[2].name, 'moreInfo'); |
| 55 | + t.deepEqual(questions[2].message, 'Do you want to add more information to your commit?'); |
| 56 | + t.deepEqual(questions[2].default, false); |
| 57 | + |
| 58 | + t.deepEqual(questions[3].type, 'editor'); |
| 59 | + t.deepEqual(questions[3].name, 'editor'); |
| 60 | + t.deepEqual(questions[3].message, 'This will let you add more information'); |
| 61 | + t.deepEqual(typeof questions[3].when, 'function'); |
| 62 | + t.deepEqual(typeof questions[3].default, 'function'); |
| 63 | +}); |
| 64 | + |
| 65 | +test('check cli', (t) => { |
| 66 | + bddStdin(bddStdin.keys.down, '\n'); |
| 67 | + const questions = [ |
| 68 | + { |
| 69 | + type: 'list', |
| 70 | + name: 'type', |
| 71 | + message: 'Select the type of your commit:', |
| 72 | + choices: [ |
| 73 | + '1', '2', '3', |
| 74 | + ], |
| 75 | + }, |
| 76 | + ]; |
| 77 | + const cli = promptConfig; |
| 78 | + return Promise.resolve(cli.prompt(questions)) |
| 79 | + .then((res) => { |
| 80 | + t.deepEqual('2', res); |
| 81 | + }); |
| 82 | +}); |
0 commit comments