diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/all.js | 1 | ||||
-rw-r--r-- | test/assertions.js | 62 | ||||
-rw-r--r-- | test/mock.js | 18 | ||||
-rw-r--r-- | test/page.js | 26 |
4 files changed, 91 insertions, 16 deletions
diff --git a/test/all.js b/test/all.js index 827a182..08be793 100644 --- a/test/all.js +++ b/test/all.js @@ -5,6 +5,7 @@ require('./readme'); require('./summary'); require('./glossary'); require('./langs'); +require('./page'); require('./parse'); require('./git'); diff --git a/test/assertions.js b/test/assertions.js new file mode 100644 index 0000000..b936995 --- /dev/null +++ b/test/assertions.js @@ -0,0 +1,62 @@ +var fs = require('fs'); +var _ = require('lodash'); +var cheerio = require('cheerio'); +var should = require('should'); + +// Assertions to test if an Output has generated a file +should.Assertion.add('file', function(file, description) { + this.params = { + actual: this.obj.toString(), + operator: 'have file ' + file, + message: description + }; + + this.obj.should.have.property('resolve').which.is.a.Function; + this.assert(fs.existsSync(this.obj.resolve(file))); +}); + +should.Assertion.add('html', function(rules, description) { + this.params = { actual: 'HTML string', operator: 'valid html', message: description }; + var $ = cheerio.load(this.obj); + + _.each(rules, function(validations, query) { + validations = _.defaults(validations || {}, { + // Select a specific element in the list of matched elements + index: null, + + // Check that there is the correct count of elements + count: 1, + + // Check attribute values + attributes: {}, + + // Trim inner text + trim: false, + + // Check inner text + text: undefined + }); + + var $el = $(query); + + // Select correct element + if (_.isNumber(validations.index)) $el = $($el.get(validations.index)); + + // Test number of elements + $el.length.should.be.equal(validations.count); + + // Test text + if (validations.text !== undefined) { + var text = $el.text(); + if (validations.trim) text = text.trim(); + text.should.be.equal(validations.text); + } + + // Test attributes + _.each(validations.attributes, function(value, name) { + var attr = $el.attr(name); + should(attr).be.ok(); + attr.should.be.equal(value); + }); + }); +}); diff --git a/test/mock.js b/test/mock.js index 1f7e7d5..ce7b027 100644 --- a/test/mock.js +++ b/test/mock.js @@ -1,15 +1,14 @@ var Q = require('q'); var _ = require('lodash'); -var fs = require('fs'); var tmp = require('tmp'); var path = require('path'); -var should = require('should'); - var Book = require('../').Book; var Output = require('../lib/output'); var NodeFS = require('../lib/fs/node'); +require('./assertions'); + // Create filesystem instance for testing var nodeFS = new NodeFS(); @@ -74,19 +73,6 @@ function outputDefaultBook(generator, files, opts) { }); } -// Assertions to test if an Output has generated a file -should.Assertion.add('file', function(file, description) { - this.params = { - actual: this.obj.toString(), - operator: 'have file ' + file, - message: description - }; - - this.obj.should.have.property('resolve').which.is.a.Function; - this.assert(fs.existsSync(this.obj.resolve(file))); -}); - - module.exports = { setupBook: setupBook, setupDefaultBook: setupDefaultBook, diff --git a/test/page.js b/test/page.js new file mode 100644 index 0000000..66c06e1 --- /dev/null +++ b/test/page.js @@ -0,0 +1,26 @@ +var mock = require('./mock'); + +describe('Page', function() { + var book; + + before(function() { + return mock.setupDefaultBook({ + 'heading.md': '# Hello\n\n## World' + }) + .then(function(_book) { + book = _book; + return book.summary.load(); + }); + }); + + it.only('should add a default ID to headings', function() { + var page = book.addPage('heading.md'); + + return page.parse() + .then(function() { + console.log(page.content); + }); + + }); + +});
\ No newline at end of file |