summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/gitbook/src/models/__tests__/book.js65
-rw-r--r--packages/gitbook/src/models/book.js2
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;
}