mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Add test for page.title variable
This commit is contained in:
+9
-3
@@ -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
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user