diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-06-10 16:37:44 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-06-10 16:37:44 +0200 |
commit | e92b661a2a9b193a85dbae998e463cf9b6299fb9 (patch) | |
tree | dac4c08a901136254a26490bf74672255778a646 /lib/plugins/__tests__/sortPlugins.js | |
parent | b9fe60915f8555fb339a8e736a0b1fa604738364 (diff) | |
download | gitbook-e92b661a2a9b193a85dbae998e463cf9b6299fb9.zip gitbook-e92b661a2a9b193a85dbae998e463cf9b6299fb9.tar.gz gitbook-e92b661a2a9b193a85dbae998e463cf9b6299fb9.tar.bz2 |
Adapt sortPlugins to only sort an ordered map of plugins
Diffstat (limited to 'lib/plugins/__tests__/sortPlugins.js')
-rw-r--r-- | lib/plugins/__tests__/sortPlugins.js | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/lib/plugins/__tests__/sortPlugins.js b/lib/plugins/__tests__/sortPlugins.js index c50c851..99955fb 100644 --- a/lib/plugins/__tests__/sortPlugins.js +++ b/lib/plugins/__tests__/sortPlugins.js @@ -1,50 +1,57 @@ -var PluginDependency = require('../../models/pluginDependency'); +var Immutable = require('immutable'); + +var Plugin = require('../../models/plugin'); var sortPlugins = require('../sortPlugins'); -var listAll = require('../listAll'); -describe('sortPlugins', function() { +/** + * 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() { it('must load themes after plugins', function() { - var deps = PluginDependency.listFromString('theme-faq'), - allPlugins = listAll(deps); + var allPlugins = Immutable.OrderedMap([ + ['hello', Plugin.createFromString('hello')], + ['theme-test', Plugin.createFromString('theme-test')], + ['world', Plugin.createFromString('world')] + ]); - var sorted = sortPlugins(allPlugins, []); - var names = sorted - .map(function(plugin) { - return plugin.getName(); - }) - .toArray(); + var sorted = sortPlugins(allPlugins); + var names = toNames(sorted); expect(names).toEqual([ - 'fontsettings', - 'sharing', - 'lunr', - 'search', - 'highlight', - 'theme-faq', - 'theme-default' + 'hello', + 'world', + 'theme-test' ]); }); - it('must load themes after plugins with a complex dependencies list', function() { - var deps = PluginDependency.listFromString('comment,theme-faq,-search,ga'), - allPlugins = listAll(deps); + it('must keep order of themes', function() { + var allPlugins = Immutable.OrderedMap([ + ['theme-test', Plugin.createFromString('theme-test')], + ['theme-test1', Plugin.createFromString('theme-test1')], + ['hello', Plugin.createFromString('hello')], + ['theme-test2', Plugin.createFromString('theme-test2')], + ['world', Plugin.createFromString('world')] + ]); - var sorted = sortPlugins(allPlugins, []); - var names = sorted - .map(function(plugin) { - return plugin.getName(); - }) - .toArray(); + var sorted = sortPlugins(allPlugins); + var names = toNames(sorted); expect(names).toEqual([ - 'ga', - 'comment', - 'fontsettings', - 'sharing', - 'lunr', - 'highlight', - 'theme-faq', - 'theme-default' + 'hello', + 'world', + 'theme-test', + 'theme-test1', + 'theme-test2' ]); }); });
\ No newline at end of file |