Skip to content

Commit

Permalink
fix(interactive-mode): Pass choices directly to inquirer (fixes #10) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nanovazquez authored Jul 10, 2018
1 parent aeb161c commit d1c6c30
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/interactive-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = (values = {}) => {
type: value.type,
message: value.describe,
default: value.default,
choices: value.options,
});
});

return prompt(questions);
};
28 changes: 17 additions & 11 deletions test/interactive-mode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ describe('interactive-mode', () => {
inquirerPromptStub = sinon.stub();
inquirerCreatePromptModuleStub = sinon.stub(inquirer, 'createPromptModule').returns(inquirerPromptStub);
interactiveMode = proxyquire('../src/interactive-mode', {
'inquirer': {createPromptModule: inquirerCreatePromptModuleStub},
'inquirer': {
createPromptModule: inquirerCreatePromptModuleStub
},
});
values = {
title: {
type: 'input',
describe: 'Message to display',
default: 'default value',
options: ['title1', 'title2']
}
};
});

describe('with no values', () => {
before(() => {
// Reset stub
inquirerPromptStub.reset();

values = undefined;
interactiveMode(values);
});
Expand All @@ -42,12 +39,19 @@ describe('interactive-mode', () => {

describe('with values', () => {
before(() => {
// Reset stub
inquirerPromptStub.reset();

values = {
title: {
type: 'input',
describe: 'Message to display',
default: 'default value',
options: ['title1', 'title2']
},
message: {
type: 'list',
describe: 'Welcome message',
choices: ['hi', 'hello', 'hola!'],
}
};
interactiveMode(values);
Expand All @@ -63,13 +67,15 @@ describe('interactive-mode', () => {

it('should properly transform the values to inquirer values', () => {
const args = inquirerPromptStub.getCalls()[0].args[0];
assert.equal(args.length, Object.keys(values).length, 'no. of values sent to inquirer');

args.forEach((question) => {
const inputValues = values[question.name];
assert.ok(inputValues, 'values');
assert.equal(question.type, inputValues.type, 'type');
assert.equal(question.message, inputValues.describe, 'message');
assert.equal(question.default, inputValues.default, 'default');
assert.equal(question.choices, inputValues.options, 'choices');
assert.equal(question.choices, inputValues.choices, 'choices');
});
});
});
Expand Down

0 comments on commit d1c6c30

Please sign in to comment.