Fix and test Book.getDefaultExt() (#1674)

This commit is contained in:
Nicolas Gaborit
2017-01-13 17:55:22 +01:00
committed by Samy Pessé
parent af80cbcd7c
commit 0342a11da0
2 changed files with 66 additions and 1 deletions
@@ -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');
});
});
});
+1 -1
View File
@@ -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;
}