mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-19 17:15:24 +00:00
Improve tests for glossary
This commit is contained in:
+17
-16
@@ -20,26 +20,27 @@ should.Assertion.add('jsonfile', function(file, description) {
|
||||
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: {}
|
||||
});
|
||||
|
||||
|
||||
should.Assertion.add('html', function(rules, description) {
|
||||
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);
|
||||
_.each(rules, function(validations, query) {
|
||||
validations = _.defaults(validations || {}, {
|
||||
count: 1,
|
||||
attributes: {}
|
||||
});
|
||||
|
||||
// Test text
|
||||
if (validations.text !== undefined) $el.text().should.be.equal(validations.text);
|
||||
var $el = $(query);
|
||||
|
||||
// Test attributes
|
||||
_.each(validations.attributes, function(value, name) {
|
||||
$el.attr(name).should.be.equal(value);
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
# Summary
|
||||
|
||||
* [Page](folder/PAGE.md)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# Page
|
||||
|
||||
Just a page in a sub-directory to test relative link to glossary.
|
||||
+29
-7
@@ -33,21 +33,43 @@ describe('Glossary', function () {
|
||||
});
|
||||
|
||||
describe('Page Integration', function() {
|
||||
var page;
|
||||
var readme, page;
|
||||
|
||||
before(function() {
|
||||
page = fs.readFileSync(
|
||||
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() {
|
||||
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."
|
||||
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
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user