Skip to content

Commit 45833ee

Browse files
committed
Add test for navigation
Update mocha and should
1 parent baf10e9 commit 45833ee

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"escape-string-regexp": "1.0.3"
3737
},
3838
"devDependencies": {
39-
"mocha": "2.2.1",
40-
"should": "5.2.0",
39+
"mocha": "2.3.2",
40+
"should": "7.1.0",
4141
"grunt": "~0.4.2",
4242
"grunt-cli": "0.1.11",
4343
"grunt-contrib-copy": "0.5.0",

test/json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('JSON generator', function () {
3535
it('should contains valid section', function() {
3636
page.should.have.property("sections").with.lengthOf(1);
3737
page.sections[0].should.have.property("content").which.is.a.String;
38-
page.sections[0].should.have.property("type").which.is.a.String.which.equal("normal");
38+
page.sections[0].should.have.property("type", "normal");
3939
});
4040

4141
it('should contains valid progress', function() {

test/navigation.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var should = require('should');
2+
3+
describe('Navigation', function () {
4+
var book;
5+
6+
before(function() {
7+
return books.parse("summary")
8+
.then(function(_book) {
9+
book = _book;
10+
});
11+
});
12+
13+
it('should correctly parse navigation as a map', function() {
14+
book.should.have.property("navigation");
15+
book.navigation.should.have.property("README.md");
16+
book.navigation.should.have.property("README.md");
17+
});
18+
19+
it('should correctly include filenames', function() {
20+
book.navigation.should.have.property("README.md");
21+
book.navigation.should.have.property("PAGE1.md");
22+
book.navigation.should.have.property("folder/PAGE2.md");
23+
book.navigation.should.not.have.property("NOTFOUND.md");
24+
});
25+
26+
it('should correctly detect next/prev for README', function() {
27+
var README = book.navigation['README.md'];
28+
29+
README.index.should.equal(0);
30+
README.should.have.property('next');
31+
should(README.prev).not.be.ok();
32+
33+
README.next.should.have.property('path');
34+
README.next.path.should.equal('PAGE1.md');
35+
});
36+
37+
it('should correctly detect next/prev a page', function() {
38+
var PAGE = book.navigation['PAGE1.md'];
39+
40+
PAGE.index.should.equal(1);
41+
PAGE.should.have.property('next');
42+
PAGE.should.have.property('prev');
43+
44+
PAGE.prev.should.have.property('path');
45+
PAGE.prev.path.should.equal('README.md');
46+
47+
PAGE.next.should.have.property('path');
48+
PAGE.next.path.should.equal('folder/PAGE2.md');
49+
});
50+
51+
it('should correctly detect next/prev for last page', function() {
52+
var PAGE = book.navigation['folder/PAGE2.md'];
53+
54+
PAGE.index.should.equal(2);
55+
PAGE.should.have.property('prev');
56+
should(PAGE.next).not.be.ok();
57+
58+
PAGE.prev.should.have.property('path');
59+
PAGE.prev.path.should.equal('PAGE1.md');
60+
});
61+
});

0 commit comments

Comments
 (0)