diff options
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | test/assertions.js | 26 | ||||
-rw-r--r-- | test/glossary.js | 36 |
3 files changed, 63 insertions, 1 deletions
diff --git a/package.json b/package.json index 51d6e14..69ccaa1 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "nunjucks-i18n": "1.0.0", "semver": "2.2.1", "npmi": "0.1.1", - "cheerio": "0.18.0", + "cheerio": "0.19.0", "gitbook-plugin-livereload": "0.0.1", "gaze": "~0.5.1", "send": "0.2.0", diff --git a/test/assertions.js b/test/assertions.js index a1c2eb9..23feaf6 100644 --- a/test/assertions.js +++ b/test/assertions.js @@ -1,6 +1,8 @@ +var _ = require('lodash'); var fs = require('fs'); var path = require('path'); var should = require('should'); +var cheerio = require('cheerio'); should.Assertion.add('file', function(file, description) { this.params = { operator: 'have file ' + file, message: description }; @@ -17,3 +19,27 @@ should.Assertion.add('jsonfile', function(file, description) { this.obj.options.should.have.property('output').which.is.a.String; this.assert(JSON.parse(fs.readFileSync(path.resolve(this.obj.options.output, file), { encoding: "utf-8" }))); }); + +should.Assertion.add('html', function(query, validations, description) { + validations = _.defaults(validations || {}, { + count: 1, + attributes: {} + }); + + + this.params = { actual: "HTML string", operator: 'valid html', message: description }; + + var $ = cheerio.load(this.obj); + var $el = $(query); + + // Test number of elements + $el.should.have.lengthOf(validations.count); + + // Test text + if (validations.text !== undefined) $el.text().should.be.equal(validations.text); + + // Test attributes + _.each(validations.attributes, function(value, name) { + $el.attr(name).should.be.equal(value); + }); +}); diff --git a/test/glossary.js b/test/glossary.js index 16ab0fc..c616a51 100644 --- a/test/glossary.js +++ b/test/glossary.js @@ -17,4 +17,40 @@ describe('Glossary', function () { book.glossary.should.have.lengthOf(2); }); }); + + describe('Generation', function() { + var book; + + before(function() { + return books.generate("glossary", "website") + .then(function(_book) { + book = _book; + }); + }); + + it('should correctly generate a GLOSSARY.html', function() { + book.should.have.file("GLOSSARY.html"); + }); + + describe('Page Integration', function() { + var page; + + before(function() { + page = fs.readFileSync( + path.join(book.options.output, "index.html"), + { encoding: "utf-8" } + ); + }); + + it('should correctly replaced terms by links', function() { + page.should.be.html(".page-inner a[href='GLOSSARY.html#test']", { + count: 1, + text: "test", + attributes: { + title: "Just a simple and easy to understand test." + } + }); + }); + }); + }); }); |