summaryrefslogtreecommitdiffstats
path: root/test/glossary.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-03-24 23:14:17 +0100
committerSamy Pessé <samypesse@gmail.com>2015-03-24 23:14:17 +0100
commitc9af209a9335ea1219c3149eb12c2daa271c9403 (patch)
tree72df3edf7a67db465ce2dacbbf204974253b818a /test/glossary.js
parent63ee94ff89d10e56d82079183c494f8129b92eae (diff)
parent48ab44a776b665b1d3627192cf82e9220ec74678 (diff)
downloadgitbook-c9af209a9335ea1219c3149eb12c2daa271c9403.zip
gitbook-c9af209a9335ea1219c3149eb12c2daa271c9403.tar.gz
gitbook-c9af209a9335ea1219c3149eb12c2daa271c9403.tar.bz2
Merge pull request #667 from GitbookIO/better-testing
Better Unit Tests
Diffstat (limited to 'test/glossary.js')
-rw-r--r--test/glossary.js97
1 files changed, 70 insertions, 27 deletions
diff --git a/test/glossary.js b/test/glossary.js
index 5deb04c..631967e 100644
--- a/test/glossary.js
+++ b/test/glossary.js
@@ -1,35 +1,78 @@
+var fs = require('fs');
var path = require('path');
-var _ = require('lodash');
-var assert = require('assert');
-var cheerio = require('cheerio');
-var fs = require("fs");
-var fsUtil = require("../lib/utils/fs");
+describe('Glossary', function () {
+ describe('Parsing', function() {
+ var book;
+ before(function() {
+ return books.parse("glossary")
+ .then(function(_book) {
+ book = _book;
+ });
+ });
-describe('Glossary Generation', function () {
- it('should correctly replace glossary terms', function(done) {
- testGeneration(books[0], "website", function(output) {
- var content = fs.readFileSync(path.join(output, "index.html"), { encoding: "utf8" });
- var $ = cheerio.load(content);
-
- var $body = $(".page-inner");
- var $a = $("a[href='GLOSSARY.html#description']");
- assert($a.length == 1);
- assert($a.text() == "description");
- }, done);
+ it('should correctly list items', function() {
+ book.should.have.property("glossary");
+ book.glossary.should.have.lengthOf(2);
+ });
});
- it('should correctly replace glossary terms in sub pages', function(done) {
- testGeneration(books[1], "website", function(output) {
- var content = fs.readFileSync(path.join(output, "sub/test1.html"), { encoding: "utf8" });
- var $ = cheerio.load(content);
-
- var $body = $(".page-inner");
- var $a = $("a[href='../GLOSSARY.html#test']");
- assert($a.length == 1);
- assert($a.text() == "test");
- assert($a.attr("title") == "a test text");
- }, done);
+ 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 readme, page;
+
+ before(function() {
+ readme = fs.readFileSync(
+ path.join(book.options.output, "index.html"),
+ { encoding: "utf-8" }
+ );
+ page = fs.readFileSync(
+ path.join(book.options.output, "folder/PAGE.html"),
+ { encoding: "utf-8" }
+ );
+ });
+
+ it('should correctly replaced terms by links', function() {
+ readme.should.be.html({
+ ".page-inner a[href='GLOSSARY.html#test']": {
+ count: 1,
+ text: "test",
+ attributes: {
+ title: "Just a simple and easy to understand test."
+ }
+ }
+ });
+ });
+
+ it('should correctly replaced terms by links (relative)', function() {
+ page.should.be.html({
+ ".page-inner a[href='../GLOSSARY.html#test']": {
+ count: 1
+ }
+ });
+ });
+
+ it('should not replace terms in codeblocks', function() {
+ readme.should.be.html({
+ ".page-inner code a": {
+ count: 0
+ }
+ });
+ });
+ });
});
});