From 8a3f80ba82bd706083015f228c551d64768a287e Mon Sep 17 00:00:00 2001 From: Samy Pesse Date: Tue, 26 Apr 2016 11:00:36 +0200 Subject: [PATCH] Add test for parsing glossary --- lib/constants/configDefault.js | 6 +++++ lib/models/config.js | 3 ++- lib/models/file.js | 9 +++++++ lib/parse/__tests__/parseGlossary.js | 37 ++++++++++++++++++++++++++++ lib/parse/parseGlossary.js | 1 - 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 lib/constants/configDefault.js create mode 100644 lib/parse/__tests__/parseGlossary.js diff --git a/lib/constants/configDefault.js b/lib/constants/configDefault.js new file mode 100644 index 000000000..0d9588391 --- /dev/null +++ b/lib/constants/configDefault.js @@ -0,0 +1,6 @@ +var Immutable = require('immutable'); +var jsonSchemaDefaults = require('json-schema-defaults'); + +var schema = require('./configSchema'); + +module.exports = Immutable.fromJS(jsonSchemaDefaults(schema)); diff --git a/lib/models/config.js b/lib/models/config.js index 8684a03e5..720ac57e4 100644 --- a/lib/models/config.js +++ b/lib/models/config.js @@ -2,10 +2,11 @@ var is = require('is'); var Immutable = require('immutable'); var File = require('./file'); +var configDefault = require('../constants/configDefault'); var Config = Immutable.Record({ file: File(), - values: Immutable.Map() + values: configDefault }, 'Config'); Config.prototype.getPath = function() { diff --git a/lib/models/file.js b/lib/models/file.js index b6b06eee0..ff7b899cc 100644 --- a/lib/models/file.js +++ b/lib/models/file.js @@ -19,6 +19,15 @@ File.prototype.getMTime = function() { return this.get('mtime'); }; +/** + Does the file exists / is set + + @return {Boolean} +*/ +File.prototype.exists = function() { + return Boolean(this.getPath()); +}; + /** Return type of file ('markdown' or 'asciidoc') diff --git a/lib/parse/__tests__/parseGlossary.js b/lib/parse/__tests__/parseGlossary.js new file mode 100644 index 000000000..1cb813c0c --- /dev/null +++ b/lib/parse/__tests__/parseGlossary.js @@ -0,0 +1,37 @@ +jest.autoMockOff(); + +describe('parseGlossary', function() { + var parseGlossary = require('../parseGlossary'); + var Book = require('../../models/book'); + var createMockFS = require('../../fs/mock'); + + pit('should parse glossary if exists', function() { + var fs = createMockFS({ + 'GLOSSARY.md': '# Glossary\n\n## Hello\nDescription for hello' + }); + var book = Book.createForFS(fs); + + return parseGlossary(book) + .then(function(resultBook) { + var glossary = resultBook.getGlossary(); + var file = glossary.getFile(); + var entries = glossary.getEntries(); + + expect(file.exists()).toBeTruthy(); + expect(entries.size).toBe(1); + }); + }); + + pit('should not fail if doesn\'t exist', function() { + var fs = createMockFS({}); + var book = Book.createForFS(fs); + + return parseGlossary(book) + .then(function(resultBook) { + var glossary = resultBook.getGlossary(); + var file = glossary.getFile(); + + expect(file.exists()).toBeFalsy(); + }); + }); +}); diff --git a/lib/parse/parseGlossary.js b/lib/parse/parseGlossary.js index 1dbfbe022..a96e5fcf6 100644 --- a/lib/parse/parseGlossary.js +++ b/lib/parse/parseGlossary.js @@ -16,7 +16,6 @@ function parseGlossary(book) { return book; } - logger.debug.ln('glossary index file found at', file.getPath()); var glossary = Glossary.createFromEntries(file, entries);