Skip to content

Commit

Permalink
feat(choices): Use choices order from conventional-changelog-metahub
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Aug 27, 2017
1 parent db1fe93 commit 51948e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/questions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {map, padEnd, maxBy} from 'lodash';
import {typesOrder} from 'conventional-changelog-metahub/types';

/**
* Create the Inquirer.js questions object.
Expand All @@ -23,7 +24,7 @@ export default function questions(options, config) {
const choices = map(allTypes, (type, key) => ({
name: `${padEnd(`${key}:`, length)} ${type.emoji} ${type.description}`,
value: key,
}));
})).sort((choice1, choice2) => (typesOrder.indexOf(choice1.value) < typesOrder.indexOf(choice2.value) ? -1 : 1));

return [
{type: 'list', name: 'type', message: "Select the type of change that you're committing:", choices},
Expand Down
8 changes: 7 additions & 1 deletion test/questions.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import {types} from 'conventional-changelog-metahub/types';
import {types, typesOrder} from 'conventional-changelog-metahub/types';
import aliases from 'conventional-changelog-metahub/aliases';
import questions from '../lib/questions';

Expand Down Expand Up @@ -86,3 +86,9 @@ test('Choices of type question are formatted properly (description of each choic
}
});
});

test('Choices are ordered based on ', t => {
questions({types, aliases}, config)[qOrder.indexOf('type')].choices.forEach((choice, index) => {
t.is(typesOrder.indexOf(choice.value), index);
});
});

0 comments on commit 51948e5

Please sign in to comment.