summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-09-15 11:31:50 +0200
committerSamy Pessé <samypesse@gmail.com>2015-09-15 11:31:50 +0200
commit45833eea9ad5fb97ab5e5095e4e4b8e3481c7d2e (patch)
tree6e65138a3cc6764525193ceeb6cd057ea0a7851b
parentbaf10e9b159b64c30ce650c83eb437675434e3e2 (diff)
downloadgitbook-45833eea9ad5fb97ab5e5095e4e4b8e3481c7d2e.zip
gitbook-45833eea9ad5fb97ab5e5095e4e4b8e3481c7d2e.tar.gz
gitbook-45833eea9ad5fb97ab5e5095e4e4b8e3481c7d2e.tar.bz2
Add test for navigation
Update mocha and should
-rw-r--r--package.json4
-rw-r--r--test/json.js2
-rw-r--r--test/navigation.js61
3 files changed, 64 insertions, 3 deletions
diff --git a/package.json b/package.json
index fec67d9..13d3259 100644
--- a/package.json
+++ b/package.json
@@ -36,8 +36,8 @@
"escape-string-regexp": "1.0.3"
},
"devDependencies": {
- "mocha": "2.2.1",
- "should": "5.2.0",
+ "mocha": "2.3.2",
+ "should": "7.1.0",
"grunt": "~0.4.2",
"grunt-cli": "0.1.11",
"grunt-contrib-copy": "0.5.0",
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');
+ });
+});