-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
119 lines (101 loc) · 3.71 KB
/
test.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
require('mocha');
var assert = require('assert');
var Base = require('templates');
var toc = require('./');
var app;
describe('verb-toc', function() {
beforeEach(function() {
app = new Base();
app.use(toc);
app.create('pages');
app.create('layouts', {viewType: 'layout'});
app.engine('.md', require('engine-base'));
});
describe('module', function() {
it('should export a function', function() {
assert.equal(typeof toc, 'function');
});
});
describe('middleware', function() {
it('should emit `toc`', function(cb) {
app.options.toc = { render: true };
app.on('toc', toc.injectToc(app));
app.layout('default', {content: 'abc {% body %} xyz'});
app.page('note.md', {
content: '\n<!-- toc -->\n\n## Foo\n This is foo.\n\n## Bar\n\nThis is bar.',
layout: 'default'
})
.render(function(err, res) {
if (err) return cb(err);
assert(res.content.indexOf('- [Foo](#foo)\n- [Bar](#bar)') !== -1);
cb();
});
});
});
describe('headings', function() {
it('should render templates in headings', function(cb) {
app.options.toc = true;
app.postRender(/./, toc.injectToc(app));
app.data({name: 'Test'});
app.layout('default', {content: 'abc {% body %} xyz'});
var page = app.page('note.md', {
content: '\n<!-- toc -->\n\n## <%= name %>\n This is foo.\n\n## Bar\n\nThis is bar.',
layout: 'default'
});
app.render(page, function(err, res) {
if (err) return cb(err);
assert.equal(res.content, 'abc \n- [Test](#test)\n- [Bar](#bar)\n\n## Test\n This is foo.\n\n## Bar\n\nThis is bar. xyz');
cb();
});
});
it('should remove `## TOC` when toc is disabled', function(cb) {
app.options.toc = false;
app.postRender(/./, toc.injectToc(app));
app.data({name: 'Test'});
app.layout('default', {content: 'abc {% body %} xyz'});
var page = app.page('note.md', {
content: '\n## TOC <!-- toc -->\n\n## <%= name %>\nThis is foo.\n\n## Bar\n\nThis is bar.',
layout: 'default'
});
app.render(page, function(err, res) {
if (err) return cb(err);
assert.equal(res.content, 'abc \n \n\n## Test\nThis is foo.\n\n## Bar\n\nThis is bar. xyz');
cb();
});
});
it('should remove `## Table of Contents` when toc is disabled', function(cb) {
app.options.toc = false;
app.postRender(/./, toc.injectToc(app));
app.data({name: 'Test'});
app.layout('default', {content: 'abc {% body %} xyz'});
var page = app.page('note.md', {
content: '\n## Table of Contents <!-- toc -->\n\n## <%= name %>\nThis is foo.\n\n## Bar\n\nThis is bar.',
layout: 'default'
});
app.render(page, function(err, res) {
if (err) return cb(err);
assert.equal(res.content, 'abc \n \n\n## Test\nThis is foo.\n\n## Bar\n\nThis is bar. xyz');
cb();
});
});
it('should render templates in headings with a helper', function(cb) {
app.helper('upper', function(str) {
return str.toUpperCase();
});
app.options.toc = true;
app.postRender(/./, toc.injectToc(app));
app.data({name: 'Test'});
app.layout('default', {content: 'abc {% body %} xyz'});
var page = app.page('note.md', {
content: '\n<!-- toc -->\n\n## <%= upper(name) %>\n This is foo.\n\n## Bar\n\nThis is bar.',
layout: 'default'
});
app.render(page, function(err, res) {
if (err) return cb(err);
assert.equal(res.content, 'abc \n- [TEST](#test)\n- [Bar](#bar)\n\n## TEST\n This is foo.\n\n## Bar\n\nThis is bar. xyz');
cb();
});
});
});
});