diff options
Diffstat (limited to 'test/page.js')
-rw-r--r-- | test/page.js | 105 |
1 files changed, 84 insertions, 21 deletions
diff --git a/test/page.js b/test/page.js index 41a0893..52d86d8 100644 --- a/test/page.js +++ b/test/page.js @@ -11,6 +11,9 @@ describe('Page', function() { 'links.md': '[link](hello.md) [link 2](variables/page/next.md) [readme](README.md)', 'links/relative.md': '[link](../hello.md) [link 2](/variables/page/next.md) [readme](../README.md)', + 'images.md': '  ', + 'images/relative.md': ' ', + 'annotations/simple.md': 'A magicien say abracadabra!', 'annotations/code.md': 'A magicien say `abracadabra`!', 'annotations/class.md': 'A magicien say <div class="no-glossary"><b>abracadabra</b>, right?</div>!', @@ -82,6 +85,27 @@ describe('Page', function() { }); }); + describe('.resolve', function() { + var page; + + before(function() { + page = book.addPage('links/relative.md'); + }); + + it('should resolve to a relative path (same folder)', function() { + page.relative('links/test.md').should.equal('test.md'); + }); + + it('should resolve to a relative path (parent folder)', function() { + page.relative('test.md').should.equal('../test.md'); + page.relative('hello/test.md').should.equal('../hello/test.md'); + }); + + it('should resolve to a relative path (child folder)', function() { + page.relative('links/hello/test.md').should.equal('hello/test.md'); + }); + }); + describe('Headings', function() { it('should add a default ID to headings', function() { var page = book.addPage('heading.md'); @@ -128,27 +152,6 @@ describe('Page', function() { }); }); - describe('.resolve', function() { - var page; - - before(function() { - page = book.addPage('links/relative.md'); - }); - - it('should resolve to a relative path (same folder)', function() { - page.relative('links/test.md').should.equal('test.md'); - }); - - it('should resolve to a relative path (parent folder)', function() { - page.relative('test.md').should.equal('../test.md'); - page.relative('hello/test.md').should.equal('../hello/test.md'); - }); - - it('should resolve to a relative path (child folder)', function() { - page.relative('links/hello/test.md').should.equal('hello/test.md'); - }); - }); - describe('Links', function() { describe('From base directory', function() { var page; @@ -217,6 +220,66 @@ describe('Page', function() { }); }); + describe('Images', function() { + describe('From base directory', function() { + var page; + + before(function() { + page = book.addPage('images.md'); + return page.toHTML(output); + }); + + it('should resolve relative images', function() { + page.content.should.be.html({ + 'img[src="test.png"]': { + count: 1 + } + }); + }); + + it('should resolve absolute images', function() { + page.content.should.be.html({ + 'img[src="test2.png"]': { + count: 1 + } + }); + }); + + it('should keep external images path', function() { + page.content.should.be.html({ + 'img[src="https:/upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"]': { + count: 1 + } + }); + }); + }); + + describe('From sub-directory', function() { + var page; + + before(function() { + page = book.addPage('images/relative.md'); + return page.toHTML(output); + }); + + it('should resolve relative images', function() { + page.content.should.be.html({ + 'img[src="test.png"]': { + count: 1 + } + }); + }); + + it('should resolve absolute images', function() { + page.content.should.be.html({ + 'img[src="../test2.png"]': { + count: 1 + } + }); + }); + }); + }); + describe('Templating Context', function() { it('should set file.mtime', function() { var page = book.addPage('variables/file/mtime.md'); |