diff --git a/package.json b/package.json index 3ba71fb0d..4418452f5 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "gh-pages": "^0.12.0", "highlightjs": "^9.8.0", "htmlparser2": "3.9.2", + "jsdom": "^9.11.0", "json": "^9.0.4", "lodash.defaultsdeep": "4.6.0", "minilog": "3.1.0", diff --git a/test/fixtures/.eslintrc.js b/test/fixtures/.eslintrc.js new file mode 100644 index 000000000..8df47e667 --- /dev/null +++ b/test/fixtures/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + 'max-len': [0] + } +}; diff --git a/test/fixtures/toolboxes.js b/test/fixtures/toolboxes.js new file mode 100644 index 000000000..e8efe6f96 --- /dev/null +++ b/test/fixtures/toolboxes.js @@ -0,0 +1,845 @@ +var jsdom = require('jsdom').jsdom; +var categories = ''; +var simple = ''; +var empty = ''; +module.exports = { + categories: jsdom(categories).body.firstElementChild, + simple: jsdom(simple).body.firstElementChild, + empty: jsdom(empty).body.firstElementChild +}; diff --git a/test/unit/util_filter-toolbox.js b/test/unit/util_filter-toolbox.js new file mode 100644 index 000000000..4334b819d --- /dev/null +++ b/test/unit/util_filter-toolbox.js @@ -0,0 +1,22 @@ +var toolboxes = require('../fixtures/toolboxes'); +var test = require('tap').test; +var filterToolbox = require('../../src/util/filter-toolbox'); + +test('categories', function (t) { + var filteredToolbox = filterToolbox(toolboxes.categories, ['operator_random']); + t.strictEqual(filteredToolbox.children.length, 1); + t.strictEqual(filteredToolbox.firstElementChild.children.length, 1); + t.end(); +}); + +test('simple', function (t) { + var filteredToolbox = filterToolbox(toolboxes.simple, ['operator_random']); + t.strictEqual(filteredToolbox.children.length, 1); + t.end(); +}); + +test('empty', function (t) { + var filteredToolbox = filterToolbox(toolboxes.empty, ['operator_random']); + t.strictEqual(filteredToolbox.children.length, 0); + t.end(); +});