Add test for page.title variable

This commit is contained in:
Samy Pessé
2016-02-15 09:44:05 +01:00
parent d6bd4a0d67
commit d7077fc7db
2 changed files with 25 additions and 8 deletions
+9 -3
View File
@@ -49,15 +49,21 @@ function setupBook(files, opts) {
}
// Setup a book with default README/SUMMARY
function setupDefaultBook(files, opts) {
function setupDefaultBook(files, summary, opts) {
var summaryContent = '# Summary \n\n' +
_.map(summary, function(article) {
return '* [' + article.title +'](' + article.path + ')';
})
.join('\n');
return setupBook(_.defaults(files || {}, {
'README.md': 'Hello',
'SUMMARY.md': '# Summary'
'SUMMARY.md': summaryContent
}), opts);
}
// Output a book with a specific generator
function outputDefaultBook(Output, files, opts) {
function outputDefaultBook(Output, files, summary, opts) {
return setupDefaultBook(files, opts)
.then(function(book) {
// Parse the book
+16 -5
View File
@@ -10,8 +10,14 @@ describe('Page', function() {
'links.md': '[link](hello.md) [readme](README.md)',
'folder/paths.md': '',
'variables/file/mtime.md': '{{ file.mtime }}',
'variables/file/path.md': '{{ file.path }}'
})
'variables/file/path.md': '{{ file.path }}',
'variables/page/title.md': '{{ page.title }}'
}, [
{
title: 'Test Variables',
path: 'variables/page/title.md'
}
])
.then(function(_book) {
book = _book;
output = new Output(book);
@@ -95,7 +101,6 @@ describe('Page', function() {
});
});
describe('Templating Context', function() {
it('should set file.mtime', function() {
var page = book.addPage('variables/file/mtime.md');
@@ -105,10 +110,16 @@ describe('Page', function() {
});
});
it('should set file.[path]', function() {
it('should set file.path', function() {
var page = book.addPage('variables/file/path.md');
return page.toHTML(output)
.should.be.fulfilledWith('<p>variables/file/path.md</p>\n');
});
it('should set page.title when page is in summary', function() {
var page = book.getPage('variables/page/title.md');
return page.toHTML(output)
.should.be.fulfilledWith('<p>Test Variables</p>\n');
});
});
});
});