summaryrefslogtreecommitdiffstats
path: root/test/assets-inliner.js
blob: 1f00b5dea33e34365b3f22f58fe366a08d068f16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var cheerio = require('cheerio');
var path = require('path');

var mock = require('./mock');
var AssetsInliner = require('../lib/output/assets-inliner');

describe('Assets Inliner Output', function() {
    var output;

    before(function() {
        var SVG = '<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 mock.outputDefaultBook(AssetsInliner, {
            'README.md': '',

            // test for SVGS
            'svg_file.md': '![image](test.svg)',
            'svg_inline.md': 'This is a svg: '+SVG,
            'test.svg': '<?xml version="1.0" encoding="UTF-8"?>' + SVG,

            // test for remote files
            'remote_png.md': '![image](https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png)',
            'remote_svg.md': '![image](https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg)',

            'SUMMARY.md': '* [svg inline](svg_inline.md)\n' +
                '* [svg file](svg_file.md)\n' +
                '* [remote png file](remote_png.md)\n' +
                '* [remote svg file](remote_svg.md)\n' +
                '\n\n'
        })
        .then(function(_output) {
            output = _output;
        });
    });

    function testImageInPage(filename) {
        var page = output.book.getPage(filename);
        var $ = cheerio.load(page.content);

        // Is there an image?
        var $img = $('img');
        $img.length.should.equal(1);

        // Does the file exists
        var src = $img.attr('src');
        output.should.have.file(src);
        path.extname(src).should.equal('.png');
    }

    describe('SVG', function() {
        it('should correctly convert SVG files to PNG', function() {
            testImageInPage('svg_file.md');
        });

        it('should correctly convert inline SVG  to PNG', function() {
            testImageInPage('svg_inline.md');
        });
    });

    describe('Remote Assets', function() {
        it('should correctly download a PNG file', function() {
            testImageInPage('remote_png.md');
        });

        it('should correctly download then convert a remote SVG to PNG', function() {
            testImageInPage('remote_svg.md');
        });
    });
});