diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-18 16:34:11 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-18 16:34:11 +0100 |
commit | 8401a674c382cd1c7ca6c6a02e4def3d237c9734 (patch) | |
tree | 6b16eb46710e5e9510483d19ef5c256c5dd93938 /test | |
parent | 3fcf1a7723a5a3b7a436974c445dbb2b79fad583 (diff) | |
download | gitbook-8401a674c382cd1c7ca6c6a02e4def3d237c9734.zip gitbook-8401a674c382cd1c7ca6c6a02e4def3d237c9734.tar.gz gitbook-8401a674c382cd1c7ca6c6a02e4def3d237c9734.tar.bz2 |
Add test for navigation in summary
Diffstat (limited to 'test')
-rw-r--r-- | test/git.js | 6 | ||||
-rw-r--r-- | test/parse.js | 4 | ||||
-rw-r--r-- | test/summary.js | 143 |
3 files changed, 148 insertions, 5 deletions
diff --git a/test/git.js b/test/git.js index 8667b07..9fd7490 100644 --- a/test/git.js +++ b/test/git.js @@ -10,14 +10,14 @@ describe('Git', function() { it('should correctly validate git urls', function() { // HTTPS - Git.isUrl('git+https://github.com/Hello/world.git').should.be.ok; + Git.isUrl('git+https://github.com/Hello/world.git').should.be.ok(); // SSH Git.isUrl('git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1').should.be.ok; // Non valid - Git.isUrl('https://github.com/Hello/world.git').should.not.be.ok; - Git.isUrl('README.md').should.not.be.ok; + Git.isUrl('https://github.com/Hello/world.git').should.not.be.ok(); + Git.isUrl('README.md').should.not.be.ok(); }); it('should parse HTTPS urls', function() { diff --git a/test/parse.js b/test/parse.js index e190107..63565ee 100644 --- a/test/parse.js +++ b/test/parse.js @@ -1,12 +1,12 @@ var mock = require('./mock'); describe('Parsing', function() { - it('should fail without SUMMARY', function() { + it('should not fail without SUMMARY', function() { return mock.setupBook({ 'README.md': '' }) .then(function(book) { - return book.parse().should.be.rejected; + return book.parse().should.be.fulfilled(); }); }); diff --git a/test/summary.js b/test/summary.js index 2744c43..a9aea5d 100644 --- a/test/summary.js +++ b/test/summary.js @@ -1,3 +1,5 @@ +var should = require('should'); + var mock = require('./mock'); describe('Summary / Table of contents', function() { @@ -36,5 +38,146 @@ describe('Summary / Table of contents', function() { book.summary.count().should.equal(3); }); }); + + describe('External', function() { + var book; + + before(function() { + return mock.setupDefaultBook({}, [ + { + title: 'Google', + path: 'https://www.google.fr' + } + ]) + .then(function(_book) { + book = _book; + return book.summary.load(); + }); + }); + + it('should correctly count articles', function() { + book.summary.count().should.equal(2); + }); + + it('should correctly signal it as external', function() { + var article = book.summary.getArticleByLevel('1'); + + should(article).be.ok(); + should(article.path).not.be.ok(); + + article.title.should.equal('Google'); + article.ref.should.equal('https:/www.google.fr'); + article.isExternal().should.be.ok; + }); + }); + + describe('Next / Previous', function() { + var book; + + before(function() { + return mock.setupDefaultBook({ + 'SUMMARY.md': '# Summary\n\n' + + '* [Hello](hello.md)\n' + + '* [Hello 2](hello2.md)\n' + + ' * [Hello 3](hello3.md)\n' + + ' * [Hello 4](hello4.md)\n' + + ' * [Hello 5](hello5.md)\n' + + '* [Hello 6](hello6.md)\n' + }) + .then(function(_book) { + book = _book; + return book.summary.load(); + }); + }); + + it('should only return a next for the readme', function() { + var article = book.summary.getArticle('README.md'); + + var prev = article.prev(); + var next = article.next(); + + should(prev).equal(null); + should(next).be.ok(); + + next.path.should.equal('hello.md'); + }); + + it('should return next/prev for a first level page', function() { + var article = book.summary.getArticle('hello.md'); + + var prev = article.prev(); + var next = article.next(); + + should(prev).be.ok(); + should(next).be.ok(); + + prev.path.should.equal('README.md'); + next.path.should.equal('hello2.md'); + }); + + it('should return next/prev for a joint -> child', function() { + var article = book.summary.getArticle('hello2.md'); + + var prev = article.prev(); + var next = article.next(); + + should(prev).be.ok(); + should(next).be.ok(); + + prev.path.should.equal('hello.md'); + next.path.should.equal('hello3.md'); + }); + + it('should return next/prev for a joint <- child', function() { + var article = book.summary.getArticle('hello3.md'); + + var prev = article.prev(); + var next = article.next(); + + should(prev).be.ok(); + should(next).be.ok(); + + prev.path.should.equal('hello2.md'); + next.path.should.equal('hello4.md'); + }); + + it('should return next/prev for a children', function() { + var article = book.summary.getArticle('hello4.md'); + + var prev = article.prev(); + var next = article.next(); + + should(prev).be.ok(); + should(next).be.ok(); + + prev.path.should.equal('hello3.md'); + next.path.should.equal('hello5.md'); + }); + + it('should return next/prev for a joint -> parent', function() { + var article = book.summary.getArticle('hello5.md'); + + var prev = article.prev(); + var next = article.next(); + + should(prev).be.ok(); + should(next).be.ok(); + + prev.path.should.equal('hello4.md'); + next.path.should.equal('hello6.md'); + }); + + it('should return prev for last', function() { + var article = book.summary.getArticle('hello6.md'); + + var prev = article.prev(); + var next = article.next(); + + should(prev).be.ok(); + should(next).be.not.ok(); + + prev.path.should.equal('hello5.md'); + }); + }); }); |