Fix listAll to add default plugins after normal ones

This commit is contained in:
Samy Pessé
2016-06-10 16:43:32 +02:00
parent e92b661a2a
commit fbc851bc4e
5 changed files with 35 additions and 45 deletions
+16 -14
View File
@@ -1,36 +1,38 @@
var PluginDependency = require('../../models/pluginDependency');
var listAll = require('../listAll');
var toNames = require('../toNames');
describe('listAll', function() {
it('must list default', function() {
var deps = PluginDependency.listFromString('ga,great');
var plugins = listAll(deps);
var names = toNames(plugins);
expect(plugins.size).toBe(8);
expect(plugins.has('ga')).toBe(true);
expect(plugins.has('great')).toBe(true);
expect(plugins.has('search')).toBe(true);
expect(names).toEqual([
'ga', 'great',
'highlight', 'search', 'lunr', 'sharing', 'fontsettings',
'theme-default' ]);
});
it('must list from array with -', function() {
var deps = PluginDependency.listFromString('ga,-great');
var plugins = listAll(deps);
var names = toNames(plugins);
expect(plugins.size).toBe(7);
expect(plugins.has('ga')).toBe(true);
expect(plugins.has('great')).toBe(false);
expect(names).toEqual([
'ga',
'highlight', 'search', 'lunr', 'sharing', 'fontsettings',
'theme-default' ]);
});
it('must remove default plugins using -', function() {
var deps = PluginDependency.listFromString('ga,-search');
var plugins = listAll(deps);
var names = toNames(plugins);
expect(plugins.size).toBe(6);
expect(plugins.has('ga')).toBe(true);
expect(plugins.has('search')).toBe(false);
expect(names).toEqual([
'ga',
'highlight', 'lunr', 'sharing', 'fontsettings',
'theme-default' ]);
});
});
+2 -14
View File
@@ -2,21 +2,9 @@ var Immutable = require('immutable');
var Plugin = require('../../models/plugin');
var sortPlugins = require('../sortPlugins');
var toNames = require('../toNames');
/**
* Return list of plugin names
* @param {OrderedMap<String:Plugin} plugins
* @return {Array<String>}
*/
function toNames(plugins) {
return plugins
.map(function(plugin) {
return plugin.getName();
})
.toArray();
}
describe.only('sortPlugins', function() {
describe('sortPlugins', function() {
it('must load themes after plugins', function() {
var allPlugins = Immutable.OrderedMap([
['hello', Plugin.createFromString('hello')],
+1 -1
View File
@@ -21,7 +21,7 @@ function listAll(deps) {
});
// Concat with default plugins
deps = DEFAULT_PLUGINS.concat(deps);
deps = deps.concat(DEFAULT_PLUGINS);
// Convert to an ordered map of Plugin
var plugins = deps
-16
View File
@@ -1,7 +1,6 @@
var Immutable = require('immutable');
var THEME_PREFIX = require('../constants/themePrefix');
var LOADING_ORDER = ['plugin', 'theme'];
var TYPE_PLUGIN = 'plugin';
var TYPE_THEME = 'theme';
@@ -32,21 +31,6 @@ function sortPlugins(plugins) {
.merge(
byTypes.get(TYPE_THEME, Immutable.OrderedMap())
);
// Sort plugins to match list in book.json
return plugins.sort(function(a, b) {
// Get order from book.json
var definitionOrder = requirementsKeys.indexOf(a.getName()) < requirementsKeys.indexOf(b.getName());
// Get order from plugins a and b type
var aType = pluginType(a.getName()),
bType = pluginType(b.getName()),
loadingOrder = LOADING_ORDER.indexOf(aType) < LOADING_ORDER.indexOf(bType);
return loadingOrder || definitionOrder ? -1 : 1;
});
}
module.exports = sortPlugins;
+16
View File
@@ -0,0 +1,16 @@
/**
* Return list of plugin names. This method is nly used in unit tests.
*
* @param {OrderedMap<String:Plugin} plugins
* @return {Array<String>}
*/
function toNames(plugins) {
return plugins
.map(function(plugin) {
return plugin.getName();
})
.toArray();
}
module.exports = toNames;