diff options
author | Nicolas Gaborit <soreine.plume@gmail.com> | 2017-01-13 17:55:22 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2017-01-13 17:55:22 +0100 |
commit | 0342a11da0835abc9317101784191b49ebef1b65 (patch) | |
tree | 8f22a736c954e4d807b6c7b1ea14ca17ebd2152d | |
parent | af80cbcd7c9c5f165da33d19c068086d884e8d9a (diff) | |
download | gitbook-0342a11da0835abc9317101784191b49ebef1b65.zip gitbook-0342a11da0835abc9317101784191b49ebef1b65.tar.gz gitbook-0342a11da0835abc9317101784191b49ebef1b65.tar.bz2 |
Fix and test Book.getDefaultExt() (#1674)
-rw-r--r-- | packages/gitbook/src/models/__tests__/book.js | 65 | ||||
-rw-r--r-- | packages/gitbook/src/models/book.js | 2 |
2 files changed, 66 insertions, 1 deletions
diff --git a/packages/gitbook/src/models/__tests__/book.js b/packages/gitbook/src/models/__tests__/book.js new file mode 100644 index 0000000..2c09546 --- /dev/null +++ b/packages/gitbook/src/models/__tests__/book.js @@ -0,0 +1,65 @@ +const Book = require('../book'); +const File = require('../file'); +const Readme = require('../readme'); +const Summary = require('../summary'); +const Glossary = require('../glossary'); + +function createMockBook(def) { + return new Book({ + readme: new Readme({ + file: new File({ path: def.readme }) + }), + + summary: new Summary({ + file: new File({ path: def.summary }) + }), + + glossary: new Glossary({ + file: new File({ path: def.glossary }) + }) + }); +} + +describe('Book', () => { + describe('getDefaultExt', () => { + it('must infer from README', () => { + const book = createMockBook({ + readme: 'README.adoc', + summary: 'SUMMARY.md', + glossary: 'GLOSSARY.md' + }); + + expect(book.getDefaultExt()).toBe('.adoc'); + }); + + it('must infer from SUMMARY', () => { + const book = createMockBook({ + readme: '', + summary: 'SUMMARY.adoc', + glossary: 'GLOSSARY.md' + }); + + expect(book.getDefaultExt()).toBe('.adoc'); + }); + + it('must infer from GLOSSARY', () => { + const book = createMockBook({ + readme: '', + summary: '', + glossary: 'GLOSSARY.adoc' + }); + + expect(book.getDefaultExt()).toBe('.adoc'); + }); + + it('must default to .md', () => { + const book = createMockBook({ + readme: '', + summary: '', + glossary: '' + }); + + expect(book.getDefaultExt()).toBe('.md'); + }); + }); +}); diff --git a/packages/gitbook/src/models/book.js b/packages/gitbook/src/models/book.js index ca445ea..1366e95 100644 --- a/packages/gitbook/src/models/book.js +++ b/packages/gitbook/src/models/book.js @@ -259,7 +259,7 @@ class Book extends Record(DEFAULTS) { const exts = clues.map((clue) => { const file = clue.getFile(); if (file.exists()) { - return file.getParser().getExtensions().first(); + return file.getParser().FILE_EXTENSIONS[0]; } else { return null; } |