Skip to content

Commit

Permalink
fix: fix wrong select choices
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Apr 28, 2019
1 parent 318d2a4 commit 1302724
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/run-questionnaire.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ async function selectPrompt(question, pickedFeatures, {preselectedFeatures, unat
}

if (multiple) {
const picked = await multiselect(question);
const picked = await multiselect({...question, choices});
if (picked && picked.length) {
picked.forEach(p => pickedFeatures.push(p));
}
} else {
const picked = await select(question);
const picked = await select({...question, choices});
if (picked) pickedFeatures.push(picked);
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/run-questionnaire.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ test('selectPrompt (multiselect) prompts for user input', async t => {

test('selectPrompt supports conditional choice', async t => {
const pickedFeatures = ['w'];
await selectPrompt({choices:[{value: 'a', if: '!w'}, {value: 'b', if: 'w'}]}, pickedFeatures, {preselectedFeatures: ['b']});
await selectPrompt({choices:[{value: 'a', if: '!w'}, {value: 'b', if: 'w'}]}, pickedFeatures, {preselectedFeatures: []});
t.deepEqual(pickedFeatures, ['w', 'b']);
await selectPrompt({choices:[{value: 'c', if: '!w'}, {value: 'd', if: 'w'}, {value: 'e'}]}, pickedFeatures, {preselectedFeatures: ['b'], _debug: [2]});
t.deepEqual(pickedFeatures, ['w', 'b', 'e']);
await selectPrompt({choices:[{value: 'c', if: '!w'}, {value: 'd', if: 'w'}, {value: 'e'}]}, pickedFeatures, {preselectedFeatures: [], _debug: [1]});
t.deepEqual(pickedFeatures, ['w', 'b', 'd']);
});

test('selectPrompt skip empty choices after condition', async t => {
Expand Down

0 comments on commit 1302724

Please sign in to comment.