diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-10 12:12:19 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-10 12:12:19 +0200 |
commit | d342d31c8e2dd8e18ddaf863edecc5b1cb82cb98 (patch) | |
tree | 6e46151d962cdc6fff7fe09ef30591a3eb31de47 | |
parent | 5b3f54fbc85dc70d6c2a5dc7fbcc70a29d4f1204 (diff) | |
download | gitbook-d342d31c8e2dd8e18ddaf863edecc5b1cb82cb98.zip gitbook-d342d31c8e2dd8e18ddaf863edecc5b1cb82cb98.tar.gz gitbook-d342d31c8e2dd8e18ddaf863edecc5b1cb82cb98.tar.bz2 |
Fix error when summary contains entry without ref
-rw-r--r-- | lib/models/__tests__/summary.js | 19 | ||||
-rw-r--r-- | lib/models/summary.js | 7 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/models/__tests__/summary.js b/lib/models/__tests__/summary.js index ad040cf..f73e49b 100644 --- a/lib/models/__tests__/summary.js +++ b/lib/models/__tests__/summary.js @@ -8,11 +8,18 @@ describe('Summary', function() { articles: [ { title: 'My First Article', - path: 'README.md' + ref: 'README.md' }, { title: 'My Second Article', - path: 'article.md' + ref: 'article.md' + }, + { + title: 'Article without ref' + }, + { + title: 'Article with absolute ref', + ref: 'https://google.fr' } ] }, @@ -33,7 +40,7 @@ describe('Summary', function() { var part = summary.getByLevel('1'); expect(part).toBeDefined(); - expect(part.getArticles().size).toBe(2); + expect(part.getArticles().size).toBe(4); }); it('can return a Part (2)', function() { @@ -66,6 +73,12 @@ describe('Summary', function() { expect(article).toBeDefined(); expect(article.getTitle()).toBe('My Second Article'); }); + + it('return undefined if not found', function() { + var article = summary.getByPath('NOT_EXISTING.md'); + + expect(article).toBeFalsy(); + }); }); describe('toText', function() { diff --git a/lib/models/summary.js b/lib/models/summary.js index 8a4afc7..70f0535 100644 --- a/lib/models/summary.js +++ b/lib/models/summary.js @@ -74,7 +74,12 @@ Summary.prototype.getByLevel = function(level) { */ Summary.prototype.getByPath = function(filePath) { return this.getArticle(function(article) { - return (LocationUtils.areIdenticalPaths(article.getPath(), filePath)); + var articlePath = article.getPath(); + + return ( + articlePath && + LocationUtils.areIdenticalPaths(articlePath, filePath) + ); }); }; |