diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/books/images/README.md | 18 | ||||
-rw-r--r-- | test/books/images/SUMMARY.md | 3 | ||||
-rw-r--r-- | test/books/images/folder/PAGE.md | 3 | ||||
-rw-r--r-- | test/books/images/test.svg | 11 | ||||
-rw-r--r-- | test/images.js | 56 |
5 files changed, 91 insertions, 0 deletions
diff --git a/test/books/images/README.md b/test/books/images/README.md new file mode 100644 index 0000000..484f410 --- /dev/null +++ b/test/books/images/README.md @@ -0,0 +1,18 @@ +# Tests for Images + +# SVG relative image + + +### Convert SVG to PNG + + +### Should only convert it once + + +### Download remote images + + +### Remote images with same filename + + + diff --git a/test/books/images/SUMMARY.md b/test/books/images/SUMMARY.md new file mode 100644 index 0000000..ec0c4fc --- /dev/null +++ b/test/books/images/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +* [Page](./folder/PAGE.md) diff --git a/test/books/images/folder/PAGE.md b/test/books/images/folder/PAGE.md new file mode 100644 index 0000000..8beb060 --- /dev/null +++ b/test/books/images/folder/PAGE.md @@ -0,0 +1,3 @@ +### Images from other folder + + diff --git a/test/books/images/test.svg b/test/books/images/test.svg new file mode 100644 index 0000000..48bba70 --- /dev/null +++ b/test/books/images/test.svg @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd"> +<svg version="1.1" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="svg-root" width="100%" height="100%" viewBox="0 0 480 360"> + <title id="test-title">basic SVG tiny doc</title> + <g id="test-body-content"> + <text font-family="Arial" font-size="14" text-anchor="middle" x="225" y="25">hello world</text> + </g> + <text id="revision" x="10" y="340" font-size="40" stroke="none" fill="black">Revision: 1.1</text> + <rect id="test-frame" x="1" y="1" width="478" height="358" fill="none" stroke="#000000"/> +</svg> + diff --git a/test/images.js b/test/images.js new file mode 100644 index 0000000..75bc529 --- /dev/null +++ b/test/images.js @@ -0,0 +1,56 @@ +var fs = require('fs'); +var _ = require('lodash'); +var path = require('path'); +var cheerio = require('cheerio'); + +describe('Images', function () { + var book, readme, $, $img, srcs; + + before(function() { + return books.generate("images", "ebook") + .then(function(_book) { + book = _book; + + readme = fs.readFileSync( + path.join(book.options.output, "index.html"), + { encoding: "utf-8" } + ); + $ = cheerio.load(readme); + $img = $("img"); + srcs = $img.map(function() { return $(this).attr("src"); }) + }); + }); + + it('should detect all images', function() { + _.uniq(srcs).should.have.lengthOf(4); + }); + + it('should keep image tags', function() { + srcs.should.have.lengthOf(5); + }); + + it('should not have .svg files', function() { + _.each(srcs, function(src) { + path.extname(src).should.not.equal(".svg"); + }); + }); + + it('should correctly convert svg images to png', function() { + _.each(srcs, function(src) { + book.should.have.file(src); + }); + }); + + it('should handle relative paths', function() { + var PAGE = fs.readFileSync( + path.join(book.options.output, "folder/PAGE.html"), + { encoding: "utf-8" } + ); + + PAGE.should.be.html({ + "img[src='../test.png']": { + count: 1 + } + }); + }); +}); |