summaryrefslogtreecommitdiffstats
path: root/lib/output/modifiers/__tests__
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output/modifiers/__tests__')
-rw-r--r--lib/output/modifiers/__tests__/addHeadingId.js26
-rw-r--r--lib/output/modifiers/__tests__/annotateText.js46
-rw-r--r--lib/output/modifiers/__tests__/fetchRemoteImages.js40
-rw-r--r--lib/output/modifiers/__tests__/highlightCode.js60
-rw-r--r--lib/output/modifiers/__tests__/inlinePng.js25
-rw-r--r--lib/output/modifiers/__tests__/resolveLinks.js104
-rw-r--r--lib/output/modifiers/__tests__/svgToImg.js25
-rw-r--r--lib/output/modifiers/__tests__/svgToPng.js33
8 files changed, 0 insertions, 359 deletions
diff --git a/lib/output/modifiers/__tests__/addHeadingId.js b/lib/output/modifiers/__tests__/addHeadingId.js
deleted file mode 100644
index a3b1d81..0000000
--- a/lib/output/modifiers/__tests__/addHeadingId.js
+++ /dev/null
@@ -1,26 +0,0 @@
-var cheerio = require('cheerio');
-var addHeadingId = require('../addHeadingId');
-
-describe('addHeadingId', function() {
- it('should add an ID if none', function() {
- var $ = cheerio.load('<h1>Hello World</h1><h2>Cool !!</h2>');
-
- return addHeadingId($)
- .then(function() {
- var html = $.html();
- expect(html).toBe('<h1 id="hello-world">Hello World</h1><h2 id="cool-">Cool !!</h2>');
- });
- });
-
- it('should not change existing IDs', function() {
- var $ = cheerio.load('<h1 id="awesome">Hello World</h1>');
-
- return addHeadingId($)
- .then(function() {
- var html = $.html();
- expect(html).toBe('<h1 id="awesome">Hello World</h1>');
- });
- });
-});
-
-
diff --git a/lib/output/modifiers/__tests__/annotateText.js b/lib/output/modifiers/__tests__/annotateText.js
deleted file mode 100644
index 67e7a10..0000000
--- a/lib/output/modifiers/__tests__/annotateText.js
+++ /dev/null
@@ -1,46 +0,0 @@
-var Immutable = require('immutable');
-var cheerio = require('cheerio');
-var GlossaryEntry = require('../../../models/glossaryEntry');
-var annotateText = require('../annotateText');
-
-describe('annotateText', function() {
- var entries = Immutable.List([
- GlossaryEntry({ name: 'Word' }),
- GlossaryEntry({ name: 'Multiple Words' })
- ]);
-
- it('should annotate text', function() {
- var $ = cheerio.load('<p>This is a word, and multiple words</p>');
-
- annotateText(entries, 'GLOSSARY.md', $);
-
- var links = $('a');
- expect(links.length).toBe(2);
-
- var word = $(links.get(0));
- expect(word.attr('href')).toBe('/GLOSSARY.md#word');
- expect(word.text()).toBe('word');
- expect(word.hasClass('glossary-term')).toBeTruthy();
-
- var words = $(links.get(1));
- expect(words.attr('href')).toBe('/GLOSSARY.md#multiple-words');
- expect(words.text()).toBe('multiple words');
- expect(words.hasClass('glossary-term')).toBeTruthy();
- });
-
- it('should not annotate scripts', function() {
- var $ = cheerio.load('<script>This is a word, and multiple words</script>');
-
- annotateText(entries, 'GLOSSARY.md', $);
- expect($('a').length).toBe(0);
- });
-
- it('should not annotate when has class "no-glossary"', function() {
- var $ = cheerio.load('<p class="no-glossary">This is a word, and multiple words</p>');
-
- annotateText(entries, 'GLOSSARY.md', $);
- expect($('a').length).toBe(0);
- });
-});
-
-
diff --git a/lib/output/modifiers/__tests__/fetchRemoteImages.js b/lib/output/modifiers/__tests__/fetchRemoteImages.js
deleted file mode 100644
index bc1704d..0000000
--- a/lib/output/modifiers/__tests__/fetchRemoteImages.js
+++ /dev/null
@@ -1,40 +0,0 @@
-var cheerio = require('cheerio');
-var tmp = require('tmp');
-var path = require('path');
-
-var URL = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png';
-
-describe('fetchRemoteImages', function() {
- var dir;
- var fetchRemoteImages = require('../fetchRemoteImages');
-
- beforeEach(function() {
- dir = tmp.dirSync();
- });
-
- it('should download image file', function() {
- var $ = cheerio.load('<img src="' + URL + '" />');
-
- return fetchRemoteImages(dir.name, 'index.html', $)
- .then(function() {
- var $img = $('img');
- var src = $img.attr('src');
-
- expect(dir.name).toHaveFile(src);
- });
- });
-
- it('should download image file and replace with relative path', function() {
- var $ = cheerio.load('<img src="' + URL + '" />');
-
- return fetchRemoteImages(dir.name, 'test/index.html', $)
- .then(function() {
- var $img = $('img');
- var src = $img.attr('src');
-
- expect(dir.name).toHaveFile(path.join('test', src));
- });
- });
-});
-
-
diff --git a/lib/output/modifiers/__tests__/highlightCode.js b/lib/output/modifiers/__tests__/highlightCode.js
deleted file mode 100644
index 75d9902..0000000
--- a/lib/output/modifiers/__tests__/highlightCode.js
+++ /dev/null
@@ -1,60 +0,0 @@
-var cheerio = require('cheerio');
-var Promise = require('../../../utils/promise');
-var highlightCode = require('../highlightCode');
-
-describe('highlightCode', function() {
- function doHighlight(lang, code) {
- return {
- text: '' + (lang || '') + '$' + code
- };
- }
-
- function doHighlightAsync(lang, code) {
- return Promise()
- .then(function() {
- return doHighlight(lang, code);
- });
- }
-
- it('should call it for normal code element', function() {
- var $ = cheerio.load('<p>This is a <code>test</code></p>');
-
- return highlightCode(doHighlight, $)
- .then(function() {
- var $code = $('code');
- expect($code.text()).toBe('$test');
- });
- });
-
- it('should call it for markdown code block', function() {
- var $ = cheerio.load('<pre><code class="lang-js">test</code></pre>');
-
- return highlightCode(doHighlight, $)
- .then(function() {
- var $code = $('code');
- expect($code.text()).toBe('js$test');
- });
- });
-
- it('should call it for asciidoc code block', function() {
- var $ = cheerio.load('<pre><code class="language-python">test</code></pre>');
-
- return highlightCode(doHighlight, $)
- .then(function() {
- var $code = $('code');
- expect($code.text()).toBe('python$test');
- });
- });
-
- it('should accept async highlighter', function() {
- var $ = cheerio.load('<pre><code class="language-python">test</code></pre>');
-
- return highlightCode(doHighlightAsync, $)
- .then(function() {
- var $code = $('code');
- expect($code.text()).toBe('python$test');
- });
- });
-});
-
-
diff --git a/lib/output/modifiers/__tests__/inlinePng.js b/lib/output/modifiers/__tests__/inlinePng.js
deleted file mode 100644
index 0073cff..0000000
--- a/lib/output/modifiers/__tests__/inlinePng.js
+++ /dev/null
@@ -1,25 +0,0 @@
-var cheerio = require('cheerio');
-var tmp = require('tmp');
-var inlinePng = require('../inlinePng');
-
-describe('inlinePng', function() {
- var dir;
-
- beforeEach(function() {
- dir = tmp.dirSync();
- });
-
- it('should write an inline PNG using data URI as a file', function() {
- var $ = cheerio.load('<img alt="GitBook Logo 20x20" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUEAYAAADdGcFOAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAACXBIWXMAAAsTAAALEwEAmpwYAAABWWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgpMwidZAAAF+klEQVRIDY3Wf5CVVR3H8c9z791fyI9dQwdQ4TTI7wEWnQZZAa/mJE4Z0OaKUuN1KoaykZxUGGHay+iIVFMoEYrUPhDCKEKW2ChT8dA0RCSxWi6EW3sYYpcfxq5C+4O9957O+7m7O/qHQ9/XzH1+nHuec57z8wkWTsKw0y6N/LxXN6KzTnEUHi8eP/l3YStSU/MdsYvBbGh8six2YXcbcgc++QkfTQkWz/81KtqDA0hlUoWnsX+5uxe5X365BB9my2bjrHNHccLk16BpS9CExjcmXMDbD6wehdyEjxbjz1uK1zn9qga6dcfnMLXeXY/qjuQ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hbSpY3wk6QOsqlCDVx2xCrInMpBmfNPQOnzKxBkkrugdOl9GKigSZZCUWIm/GqwDtLUI5D+WAOlb9wKP0YvQLbjZSjsaYaL/n0/FA3fDtnCGihK5UYjCK+ZDr+TDIKLdm2Fs1UOzo76F5wO74XSZj0S6d7RCMLkCshcXALZxaWQRjXDZQ62oRAdCeG/Ju5HELX2QFH3C0hkRy6GovyfwF58AoVbguOxyB2H7/I34Gf11yANnQSp7Vr4MbQH0vg7kbNNp5AM3UrIVDchnz56B1Jm573wW9gZSFVPwO/hefg5FsIvN09CchtQCIOFw/F5U8ii3CZn4cqo7C8YlXEPYkx9cacZl00+iwnprrtwVdj1Q/gXmAs/pu6LZc9XQOGgSvh19n2cDZN341g2EcfxTEGwH/RewqlMsUfbbWIGLjUG+j/j9nokD1beiOvLS5dhjr30Gu6ZnivgdtM/6VJvY1+6pBHbH+h9CX84vfMxNJtisYVFlys+WNCIZJNmIsjohlhNSQC3f8R55H+y/hjkN8GPR9ndCLJxT4/3n0Px51ay8XQnNrYfDJHf//Fc0oMrEZSeeQGJ7+Z+gKCgLbHNWgXnB9FlYt5JaN38JIINC95EakjtAqQeuUx21c5B6tEFf0fSfbEFQf28Z6D6y+X/H0jf40QQJhYwAAAAAElFTkSuQmCC"/>');
-
- return inlinePng(dir.name, 'index.html', $)
- .then(function() {
- var $img = $('img');
- var src = $img.attr('src');
-
- expect(dir.name).toHaveFile(src);
- });
- });
-});
-
-
diff --git a/lib/output/modifiers/__tests__/resolveLinks.js b/lib/output/modifiers/__tests__/resolveLinks.js
deleted file mode 100644
index 8904c11..0000000
--- a/lib/output/modifiers/__tests__/resolveLinks.js
+++ /dev/null
@@ -1,104 +0,0 @@
-var path = require('path');
-var cheerio = require('cheerio');
-var resolveLinks = require('../resolveLinks');
-
-describe('resolveLinks', function() {
- function resolveFileBasic(href) {
- return 'fakeDir/' + href;
- }
-
- function resolveFileCustom(href) {
- if (path.extname(href) == '.md') {
- return href.slice(0, -3) + '.html';
- }
-
- return href;
- }
-
- describe('Absolute path', function() {
- var TEST = '<p>This is a <a href="/test/cool.md"></a></p>';
-
- it('should resolve path starting by "/" in root directory', function() {
- var $ = cheerio.load(TEST);
-
- return resolveLinks('hello.md', resolveFileBasic, $)
- .then(function() {
- var link = $('a');
- expect(link.attr('href')).toBe('fakeDir/test/cool.md');
- });
- });
-
- it('should resolve path starting by "/" in child directory', function() {
- var $ = cheerio.load(TEST);
-
- return resolveLinks('afolder/hello.md', resolveFileBasic, $)
- .then(function() {
- var link = $('a');
- expect(link.attr('href')).toBe('../fakeDir/test/cool.md');
- });
- });
- });
-
- describe('Anchor', function() {
- it('should prevent anchors in resolution', function() {
- var TEST = '<p>This is a <a href="test/cool.md#an-anchor"></a></p>';
- var $ = cheerio.load(TEST);
-
- return resolveLinks('hello.md', resolveFileCustom, $)
- .then(function() {
- var link = $('a');
- expect(link.attr('href')).toBe('test/cool.html#an-anchor');
- });
- });
-
- it('should ignore pure anchor links', function() {
- var TEST = '<p>This is a <a href="#an-anchor"></a></p>';
- var $ = cheerio.load(TEST);
-
- return resolveLinks('hello.md', resolveFileCustom, $)
- .then(function() {
- var link = $('a');
- expect(link.attr('href')).toBe('#an-anchor');
- });
- });
- });
-
- describe('Custom Resolver', function() {
- var TEST = '<p>This is a <a href="/test/cool.md"></a> <a href="afile.png"></a></p>';
-
- it('should resolve path correctly for absolute path', function() {
- var $ = cheerio.load(TEST);
-
- return resolveLinks('hello.md', resolveFileCustom, $)
- .then(function() {
- var link = $('a').first();
- expect(link.attr('href')).toBe('test/cool.html');
- });
- });
-
- it('should resolve path correctly for absolute path (2)', function() {
- var $ = cheerio.load(TEST);
-
- return resolveLinks('afodler/hello.md', resolveFileCustom, $)
- .then(function() {
- var link = $('a').first();
- expect(link.attr('href')).toBe('../test/cool.html');
- });
- });
- });
-
- describe('External link', function() {
- var TEST = '<p>This is a <a href="http://www.github.com">external link</a></p>';
-
- it('should have target="_blank" attribute', function() {
- var $ = cheerio.load(TEST);
-
- return resolveLinks('hello.md', resolveFileBasic, $)
- .then(function() {
- var link = $('a');
- expect(link.attr('target')).toBe('_blank');
- });
- });
- });
-
-});
diff --git a/lib/output/modifiers/__tests__/svgToImg.js b/lib/output/modifiers/__tests__/svgToImg.js
deleted file mode 100644
index 5fe9796..0000000
--- a/lib/output/modifiers/__tests__/svgToImg.js
+++ /dev/null
@@ -1,25 +0,0 @@
-var cheerio = require('cheerio');
-var tmp = require('tmp');
-
-describe('svgToImg', function() {
- var dir;
- var svgToImg = require('../svgToImg');
-
- beforeEach(function() {
- dir = tmp.dirSync();
- });
-
- it('should write svg as a file', function() {
- var $ = cheerio.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>');
-
- return svgToImg(dir.name, 'index.html', $)
- .then(function() {
- var $img = $('img');
- var src = $img.attr('src');
-
- expect(dir.name).toHaveFile(src);
- });
- });
-});
-
-
diff --git a/lib/output/modifiers/__tests__/svgToPng.js b/lib/output/modifiers/__tests__/svgToPng.js
deleted file mode 100644
index dbb3502..0000000
--- a/lib/output/modifiers/__tests__/svgToPng.js
+++ /dev/null
@@ -1,33 +0,0 @@
-var cheerio = require('cheerio');
-var tmp = require('tmp');
-var path = require('path');
-
-var svgToImg = require('../svgToImg');
-var svgToPng = require('../svgToPng');
-
-describe('svgToPng', function() {
- var dir;
-
- beforeEach(function() {
- dir = tmp.dirSync();
- });
-
- it('should write svg as png file', function() {
- var $ = cheerio.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>');
- var fileName = 'index.html';
-
- return svgToImg(dir.name, fileName, $)
- .then(function() {
- return svgToPng(dir.name, fileName, $);
- })
- .then(function() {
- var $img = $('img');
- var src = $img.attr('src');
-
- expect(dir.name).toHaveFile(src);
- expect(path.extname(src)).toBe('.png');
- });
- });
-});
-
-