summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-09-15 12:27:07 +0200
committerSamy Pessé <samypesse@gmail.com>2015-09-15 12:27:07 +0200
commit57a0c3bad8333d93815257d7ff603bc34b8b3f4d (patch)
treecf5f447e84e3b4ac2d74d7092d8c522bd6e67b79 /test
parent463a947df1e5c8c862c555a5b0ae675e356a0d5c (diff)
parent2a52326a454a23444bd8f0395a9ab8a1f5f68831 (diff)
downloadgitbook-57a0c3bad8333d93815257d7ff603bc34b8b3f4d.zip
gitbook-57a0c3bad8333d93815257d7ff603bc34b8b3f4d.tar.gz
gitbook-57a0c3bad8333d93815257d7ff603bc34b8b3f4d.tar.bz2
Merge pull request #929 from GitbookIO/feature/improve_resolve
Improve paths resolving for conrefs
Diffstat (limited to 'test')
-rw-r--r--test/books/conrefs/README.md6
-rw-r--r--test/configuration.js8
-rw-r--r--test/conrefs.js31
-rw-r--r--test/ebook.js19
-rw-r--r--test/json.js2
-rw-r--r--test/navigation.js61
-rw-r--r--test/plugins.js7
-rw-r--r--test/resolve.js61
8 files changed, 184 insertions, 11 deletions
diff --git a/test/books/conrefs/README.md b/test/books/conrefs/README.md
index 7f56eed..804a77a 100644
--- a/test/books/conrefs/README.md
+++ b/test/books/conrefs/README.md
@@ -3,8 +3,10 @@
### Relative
<p id="t1">{% include "./hello.md" %}</p>
+<p id="t2">{% include "/hello.md" %}</p>
### Git
-<p id="t2">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}</p>
-<p id="t3">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}</p>
+<p id="t3">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}</p>
+<p id="t4">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}</p>
+<p id="t5">{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}</p>
diff --git a/test/configuration.js b/test/configuration.js
index eedec49..2cff26e 100644
--- a/test/configuration.js
+++ b/test/configuration.js
@@ -29,4 +29,12 @@ describe('Configuration', function () {
book.options.title.should.be.equal("js-config");
});
});
+
+ it('should provide configuration on book.config.get', function() {
+ return books.parse("basic")
+ .then(function(book) {
+ book.config.get('description').should.be.equal("Default description for the book.");
+ book.getConfig('description').should.be.equal("Default description for the book.");
+ });
+ });
});
diff --git a/test/conrefs.js b/test/conrefs.js
index 8d6a181..7e044f5 100644
--- a/test/conrefs.js
+++ b/test/conrefs.js
@@ -26,15 +26,40 @@ describe('ConRefs', function () {
});
});
- it('should handle git references', function() {
+ it('should handle local references with absolute paths', function() {
readme.should.be.html({
".page-inner p#t2": {
count: 1,
- text: "Hello from git",
+ text: "Hello World",
trim: true
- },
+ }
+ });
+ });
+
+ it('should correctly include file from git reference', function() {
+ readme.should.be.html({
".page-inner p#t3": {
count: 1,
+ text: "Hello from git",
+ trim: true
+ }
+ });
+ });
+
+ it('should correctly handle deep include in git reference', function() {
+ readme.should.be.html({
+ ".page-inner p#t4": {
+ count: 1,
+ text: "First Hello. Hello from git",
+ trim: true
+ }
+ });
+ });
+
+ it('should correctly handle absolute include in git reference', function() {
+ readme.should.be.html({
+ ".page-inner p#t5": {
+ count: 1,
text: "First Hello. Hello from git",
trim: true
}
diff --git a/test/ebook.js b/test/ebook.js
index 9b353d2..033fd04 100644
--- a/test/ebook.js
+++ b/test/ebook.js
@@ -37,12 +37,23 @@ describe('eBook generator', function () {
path.join(book.options.output, "index.html"),
{ encoding: "utf-8" }
);
+
+ // There are 2 styles (one from plugin-highlight and the new style)
PAGE.should.be.html({
"link": {
- count: 1,
- attributes: {
- href: "./styles/print.css"
- }
+ count: 2
+ }
+ });
+
+ PAGE.should.be.html({
+ "link[href='./styles/print.css']": {
+ count: 1
+ }
+ });
+
+ PAGE.should.be.html({
+ "link[href='gitbook/plugins/gitbook-plugin-highlight/ebook.css']": {
+ count: 1
}
});
});
diff --git a/test/json.js b/test/json.js
index 0e50237..758cfd7 100644
--- a/test/json.js
+++ b/test/json.js
@@ -35,7 +35,7 @@ describe('JSON generator', function () {
it('should contains valid section', function() {
page.should.have.property("sections").with.lengthOf(1);
page.sections[0].should.have.property("content").which.is.a.String;
- page.sections[0].should.have.property("type").which.is.a.String.which.equal("normal");
+ page.sections[0].should.have.property("type", "normal");
});
it('should contains valid progress', function() {
diff --git a/test/navigation.js b/test/navigation.js
new file mode 100644
index 0000000..ddcc86e
--- /dev/null
+++ b/test/navigation.js
@@ -0,0 +1,61 @@
+var should = require('should');
+
+describe('Navigation', function () {
+ var book;
+
+ before(function() {
+ return books.parse("summary")
+ .then(function(_book) {
+ book = _book;
+ });
+ });
+
+ it('should correctly parse navigation as a map', function() {
+ book.should.have.property("navigation");
+ book.navigation.should.have.property("README.md");
+ book.navigation.should.have.property("README.md");
+ });
+
+ it('should correctly include filenames', function() {
+ book.navigation.should.have.property("README.md");
+ book.navigation.should.have.property("PAGE1.md");
+ book.navigation.should.have.property("folder/PAGE2.md");
+ book.navigation.should.not.have.property("NOTFOUND.md");
+ });
+
+ it('should correctly detect next/prev for README', function() {
+ var README = book.navigation['README.md'];
+
+ README.index.should.equal(0);
+ README.should.have.property('next');
+ should(README.prev).not.be.ok();
+
+ README.next.should.have.property('path');
+ README.next.path.should.equal('PAGE1.md');
+ });
+
+ it('should correctly detect next/prev a page', function() {
+ var PAGE = book.navigation['PAGE1.md'];
+
+ PAGE.index.should.equal(1);
+ PAGE.should.have.property('next');
+ PAGE.should.have.property('prev');
+
+ PAGE.prev.should.have.property('path');
+ PAGE.prev.path.should.equal('README.md');
+
+ PAGE.next.should.have.property('path');
+ PAGE.next.path.should.equal('folder/PAGE2.md');
+ });
+
+ it('should correctly detect next/prev for last page', function() {
+ var PAGE = book.navigation['folder/PAGE2.md'];
+
+ PAGE.index.should.equal(2);
+ PAGE.should.have.property('prev');
+ should(PAGE.next).not.be.ok();
+
+ PAGE.prev.should.have.property('path');
+ PAGE.prev.path.should.equal('PAGE1.md');
+ });
+});
diff --git a/test/plugins.js b/test/plugins.js
index cc9c8e6..6d5b9de 100644
--- a/test/plugins.js
+++ b/test/plugins.js
@@ -90,7 +90,12 @@ describe('Plugins', function () {
it('should extend books plugins', function() {
var resources = book.plugins.resources("ebook");
- resources["css"].should.have.lengthOf(1);
+
+ // There is resources from highlight plugin and this plugin
+ resources["css"].should.have.lengthOf(2);
+ should.exist(_.find(resources["css"], {
+ path: './resources/test'
+ }));
});
});
});
diff --git a/test/resolve.js b/test/resolve.js
new file mode 100644
index 0000000..b31a10d
--- /dev/null
+++ b/test/resolve.js
@@ -0,0 +1,61 @@
+var fs = require('fs');
+var path = require('path');
+
+describe('Resolve Files', function () {
+ var book;
+
+ before(function() {
+ return books.parse("basic")
+ .then(function(_book) {
+ book = _book;
+ });
+ });
+
+ describe('book.fileIsInBook', function() {
+ it('should return true for correct paths', function() {
+ book.fileIsInBook(path.join(book.root, 'README.md')).should.equal(true);
+ book.fileIsInBook(path.join(book.root, 'styles/website.css')).should.equal(true);
+ });
+
+ it('should return true for root folder', function() {
+ book.fileIsInBook(path.join(book.root, './')).should.equal(true);
+ book.fileIsInBook(book.root).should.equal(true);
+ });
+
+ it('should return false for files out of scope', function() {
+ book.fileIsInBook(path.join(book.root, '../')).should.equal(false);
+ book.fileIsInBook('README.md').should.equal(false);
+ book.fileIsInBook(path.resolve(book.root, '../README.md')).should.equal(false);
+ });
+
+ it('should correctly handle windows paths', function() {
+ book.fileIsInBook(path.join(book.root, '\\styles\\website.css')).should.equal(true);
+ });
+ });
+
+ describe('book.resolve', function() {
+ it('should resolve a file to its absolute path', function() {
+ book.resolve('README.md').should.equal(path.resolve(book.root, 'README.md'));
+ book.resolve('website/README.md').should.equal(path.resolve(book.root, 'website/README.md'));
+ });
+
+ it('should correctly handle windows paths', function() {
+ book.resolve('styles\\website.css').should.equal(path.resolve(book.root, 'styles\\website.css'));
+ });
+
+ it('should correctly resolve all arguments', function() {
+ book.resolve('test', 'hello', '..', 'README.md').should.equal(path.resolve(book.root, 'test/README.md'));
+ });
+
+ it('should correctly resolve to root folder', function() {
+ book.resolve('test', '/README.md').should.equal(path.resolve(book.root, 'README.md'));
+ book.resolve('test', '\\README.md').should.equal(path.resolve(book.root, 'README.md'));
+ });
+
+ it('should throw an error for file out of book', function() {
+ (function() {
+ return book.resolve('../README.md');
+ }).should.throw();
+ });
+ });
+});