summaryrefslogtreecommitdiffstats
path: root/lib/models/__tests__
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/__tests__')
-rw-r--r--lib/models/__tests__/config.js90
-rw-r--r--lib/models/__tests__/glossary.js40
-rw-r--r--lib/models/__tests__/glossaryEntry.js15
-rw-r--r--lib/models/__tests__/page.js28
-rw-r--r--lib/models/__tests__/plugin.js27
-rw-r--r--lib/models/__tests__/pluginDependency.js80
-rw-r--r--lib/models/__tests__/summary.js94
-rw-r--r--lib/models/__tests__/summaryArticle.js53
-rw-r--r--lib/models/__tests__/summaryPart.js23
-rw-r--r--lib/models/__tests__/templateBlock.js205
-rw-r--r--lib/models/__tests__/templateEngine.js51
11 files changed, 0 insertions, 706 deletions
diff --git a/lib/models/__tests__/config.js b/lib/models/__tests__/config.js
deleted file mode 100644
index abad754..0000000
--- a/lib/models/__tests__/config.js
+++ /dev/null
@@ -1,90 +0,0 @@
-var Immutable = require('immutable');
-var Config = require('../config');
-
-describe('Config', function() {
- var config = Config.createWithValues({
- hello: {
- world: 1,
- test: 'Hello',
- isFalse: false
- }
- });
-
- describe('getValue', function() {
- it('must return value as immutable', function() {
- var value = config.getValue('hello');
- expect(Immutable.Map.isMap(value)).toBeTruthy();
- });
-
- it('must return deep value', function() {
- var value = config.getValue('hello.world');
- expect(value).toBe(1);
- });
-
- it('must return default value if non existant', function() {
- var value = config.getValue('hello.nonExistant', 'defaultValue');
- expect(value).toBe('defaultValue');
- });
-
- it('must not return default value for falsy values', function() {
- var value = config.getValue('hello.isFalse', 'defaultValue');
- expect(value).toBe(false);
- });
- });
-
- describe('setValue', function() {
- it('must set value as immutable', function() {
- var testConfig = config.setValue('hello', {
- 'cool': 1
- });
- var value = testConfig.getValue('hello');
-
- expect(Immutable.Map.isMap(value)).toBeTruthy();
- expect(value.size).toBe(1);
- expect(value.has('cool')).toBeTruthy();
- });
-
- it('must set deep value', function() {
- var testConfig = config.setValue('hello.world', 2);
- var hello = testConfig.getValue('hello');
- var world = testConfig.getValue('hello.world');
-
- expect(Immutable.Map.isMap(hello)).toBeTruthy();
- expect(hello.size).toBe(3);
-
- expect(world).toBe(2);
- });
- });
-
- describe('toReducedVersion', function() {
- it('must only return diffs for simple values', function() {
- var _config = Config.createWithValues({
- gitbook: '3.0.0'
- });
-
- var reducedVersion = _config.toReducedVersion();
-
- expect(reducedVersion.toJS()).toEqual({
- gitbook: '3.0.0'
- });
- });
-
- it('must only return diffs for deep values', function() {
- var _config = Config.createWithValues({
- structure: {
- readme: 'intro.md'
- }
- });
-
- var reducedVersion = _config.toReducedVersion();
-
- expect(reducedVersion.toJS()).toEqual({
- structure: {
- readme: 'intro.md'
- }
- });
- });
- });
-});
-
-
diff --git a/lib/models/__tests__/glossary.js b/lib/models/__tests__/glossary.js
deleted file mode 100644
index 5bf64dc..0000000
--- a/lib/models/__tests__/glossary.js
+++ /dev/null
@@ -1,40 +0,0 @@
-var File = require('../file');
-var Glossary = require('../glossary');
-var GlossaryEntry = require('../glossaryEntry');
-
-describe('Glossary', function() {
- var glossary = Glossary.createFromEntries(File(), [
- {
- name: 'Hello World',
- description: 'Awesome!'
- },
- {
- name: 'JavaScript',
- description: 'This is a cool language'
- }
- ]);
-
- describe('createFromEntries', function() {
- it('must add all entries', function() {
- var entries = glossary.getEntries();
- expect(entries.size).toBe(2);
- });
-
- it('must add entries as GlossaryEntries', function() {
- var entries = glossary.getEntries();
- var entry = entries.get('hello-world');
- expect(entry instanceof GlossaryEntry).toBeTruthy();
- });
- });
-
- describe('toText', function() {
- it('return as markdown', function() {
- return glossary.toText('.md')
- .then(function(text) {
- expect(text).toContain('# Glossary');
- });
- });
- });
-});
-
-
diff --git a/lib/models/__tests__/glossaryEntry.js b/lib/models/__tests__/glossaryEntry.js
deleted file mode 100644
index 833115d..0000000
--- a/lib/models/__tests__/glossaryEntry.js
+++ /dev/null
@@ -1,15 +0,0 @@
-var GlossaryEntry = require('../glossaryEntry');
-
-describe('GlossaryEntry', function() {
- describe('getID', function() {
- it('must return a normalized ID', function() {
- var entry = new GlossaryEntry({
- name: 'Hello World'
- });
-
- expect(entry.getID()).toBe('hello-world');
- });
- });
-});
-
-
diff --git a/lib/models/__tests__/page.js b/lib/models/__tests__/page.js
deleted file mode 100644
index 479d276..0000000
--- a/lib/models/__tests__/page.js
+++ /dev/null
@@ -1,28 +0,0 @@
-var Immutable = require('immutable');
-var Page = require('../page');
-
-describe('Page', function() {
-
- describe('toText', function() {
- it('must not prepend frontmatter if no attributes', function() {
- var page = Page().merge({
- content: 'Hello World'
- });
-
- expect(page.toText()).toBe('Hello World');
- });
-
- it('must prepend frontmatter if attributes', function() {
- var page = Page().merge({
- content: 'Hello World',
- attributes: Immutable.fromJS({
- hello: 'world'
- })
- });
-
- expect(page.toText()).toBe('---\nhello: world\n---\n\nHello World');
- });
- });
-});
-
-
diff --git a/lib/models/__tests__/plugin.js b/lib/models/__tests__/plugin.js
deleted file mode 100644
index b229664..0000000
--- a/lib/models/__tests__/plugin.js
+++ /dev/null
@@ -1,27 +0,0 @@
-describe('Plugin', function() {
- var Plugin = require('../plugin');
-
- describe('createFromString', function() {
- it('must parse name', function() {
- var plugin = Plugin.createFromString('hello');
- expect(plugin.getName()).toBe('hello');
- expect(plugin.getVersion()).toBe('*');
- });
-
- it('must parse version', function() {
- var plugin = Plugin.createFromString('hello@1.0.0');
- expect(plugin.getName()).toBe('hello');
- expect(plugin.getVersion()).toBe('1.0.0');
- });
- });
-
- describe('isLoaded', function() {
- it('must return false for empty plugin', function() {
- var plugin = Plugin.createFromString('hello');
- expect(plugin.isLoaded()).toBe(false);
- });
-
- });
-});
-
-
diff --git a/lib/models/__tests__/pluginDependency.js b/lib/models/__tests__/pluginDependency.js
deleted file mode 100644
index cb04cf2..0000000
--- a/lib/models/__tests__/pluginDependency.js
+++ /dev/null
@@ -1,80 +0,0 @@
-var Immutable = require('immutable');
-var PluginDependency = require('../pluginDependency');
-
-describe('PluginDependency', function() {
- describe('createFromString', function() {
- it('must parse name', function() {
- var plugin = PluginDependency.createFromString('hello');
- expect(plugin.getName()).toBe('hello');
- expect(plugin.getVersion()).toBe('*');
- });
-
- it('must parse state', function() {
- var plugin = PluginDependency.createFromString('-hello');
- expect(plugin.getName()).toBe('hello');
- expect(plugin.isEnabled()).toBe(false);
- });
-
- describe('Version', function() {
- it('must parse version', function() {
- var plugin = PluginDependency.createFromString('hello@1.0.0');
- expect(plugin.getName()).toBe('hello');
- expect(plugin.getVersion()).toBe('1.0.0');
- });
-
- it('must parse semver', function() {
- var plugin = PluginDependency.createFromString('hello@>=4.0.0');
- expect(plugin.getName()).toBe('hello');
- expect(plugin.getVersion()).toBe('>=4.0.0');
- });
- });
-
- describe('GIT Version', function() {
- it('must handle HTTPS urls', function() {
- var plugin = PluginDependency.createFromString('hello@git+https://github.com/GitbookIO/plugin-ga.git');
- expect(plugin.getName()).toBe('hello');
- expect(plugin.getVersion()).toBe('git+https://github.com/GitbookIO/plugin-ga.git');
- });
-
- it('must handle SSH urls', function() {
- var plugin = PluginDependency.createFromString('hello@git+ssh://samy@github.com/GitbookIO/plugin-ga.git');
- expect(plugin.getName()).toBe('hello');
- expect(plugin.getVersion()).toBe('git+ssh://samy@github.com/GitbookIO/plugin-ga.git');
- });
- });
-
- describe('listToArray', function() {
- it('must create an array from a list of plugin dependencies', function() {
- var list = PluginDependency.listToArray(Immutable.List([
- PluginDependency.createFromString('hello@1.0.0'),
- PluginDependency.createFromString('noversion'),
- PluginDependency.createFromString('-disabled')
- ]));
-
- expect(list).toEqual([
- 'hello@1.0.0',
- 'noversion',
- '-disabled'
- ]);
- });
- });
-
- describe('listFromArray', function() {
- it('must create an array from a list of plugin dependencies', function() {
- var arr = Immutable.fromJS([
- 'hello@1.0.0',
- {
- 'name': 'plugin-ga',
- 'version': 'git+ssh://samy@github.com/GitbookIO/plugin-ga.git'
- }
- ]);
- var list = PluginDependency.listFromArray(arr);
-
- expect(list.first().getName()).toBe('hello');
- expect(list.first().getVersion()).toBe('1.0.0');
- expect(list.last().getName()).toBe('plugin-ga');
- expect(list.last().getVersion()).toBe('git+ssh://samy@github.com/GitbookIO/plugin-ga.git');
- });
- });
- });
-});
diff --git a/lib/models/__tests__/summary.js b/lib/models/__tests__/summary.js
deleted file mode 100644
index 29c9330..0000000
--- a/lib/models/__tests__/summary.js
+++ /dev/null
@@ -1,94 +0,0 @@
-
-describe('Summary', function() {
- var File = require('../file');
- var Summary = require('../summary');
-
- var summary = Summary.createFromParts(File(), [
- {
- articles: [
- {
- title: 'My First Article',
- ref: 'README.md'
- },
- {
- title: 'My Second Article',
- ref: 'article.md'
- },
- {
- title: 'Article without ref'
- },
- {
- title: 'Article with absolute ref',
- ref: 'https://google.fr'
- }
- ]
- },
- {
- title: 'Test'
- }
- ]);
-
- describe('createFromEntries', function() {
- it('must add all parts', function() {
- var parts = summary.getParts();
- expect(parts.size).toBe(2);
- });
- });
-
- describe('getByLevel', function() {
- it('can return a Part', function() {
- var part = summary.getByLevel('1');
-
- expect(part).toBeDefined();
- expect(part.getArticles().size).toBe(4);
- });
-
- it('can return a Part (2)', function() {
- var part = summary.getByLevel('2');
-
- expect(part).toBeDefined();
- expect(part.getTitle()).toBe('Test');
- expect(part.getArticles().size).toBe(0);
- });
-
- it('can return an Article', function() {
- var article = summary.getByLevel('1.1');
-
- expect(article).toBeDefined();
- expect(article.getTitle()).toBe('My First Article');
- });
- });
-
- describe('getByPath', function() {
- it('return correct article', function() {
- var article = summary.getByPath('README.md');
-
- expect(article).toBeDefined();
- expect(article.getTitle()).toBe('My First Article');
- });
-
- it('return correct article', function() {
- var article = summary.getByPath('article.md');
-
- 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() {
- it('return as markdown', function() {
- return summary.toText('.md')
- .then(function(text) {
- expect(text).toContain('# Summary');
- });
- });
- });
-});
-
-
diff --git a/lib/models/__tests__/summaryArticle.js b/lib/models/__tests__/summaryArticle.js
deleted file mode 100644
index 22a7a20..0000000
--- a/lib/models/__tests__/summaryArticle.js
+++ /dev/null
@@ -1,53 +0,0 @@
-var SummaryArticle = require('../summaryArticle');
-var File = require('../file');
-
-describe('SummaryArticle', function() {
- describe('createChildLevel', function() {
- it('must create the right level', function() {
- var article = SummaryArticle.create({}, '1.1');
- expect(article.createChildLevel()).toBe('1.1.1');
- });
-
- it('must create the right level when has articles', function() {
- var article = SummaryArticle.create({
- articles: [
- {
- title: 'Test'
- }
- ]
- }, '1.1');
- expect(article.createChildLevel()).toBe('1.1.2');
- });
- });
-
- describe('isFile', function() {
- it('must return true when exactly the file', function() {
- var article = SummaryArticle.create({
- ref: 'hello.md'
- }, '1.1');
- var file = File.createWithFilepath('hello.md');
-
- expect(article.isFile(file)).toBe(true);
- });
-
- it('must return true when path is not normalized', function() {
- var article = SummaryArticle.create({
- ref: '/hello.md'
- }, '1.1');
- var file = File.createWithFilepath('hello.md');
-
- expect(article.isFile(file)).toBe(true);
- });
-
- it('must return false when has anchor', function() {
- var article = SummaryArticle.create({
- ref: 'hello.md#world'
- }, '1.1');
- var file = File.createWithFilepath('hello.md');
-
- expect(article.isFile(file)).toBe(false);
- });
- });
-});
-
-
diff --git a/lib/models/__tests__/summaryPart.js b/lib/models/__tests__/summaryPart.js
deleted file mode 100644
index 8ee50b6..0000000
--- a/lib/models/__tests__/summaryPart.js
+++ /dev/null
@@ -1,23 +0,0 @@
-var SummaryPart = require('../summaryPart');
-
-describe('SummaryPart', function() {
- describe('createChildLevel', function() {
- it('must create the right level', function() {
- var article = SummaryPart.create({}, '1');
- expect(article.createChildLevel()).toBe('1.1');
- });
-
- it('must create the right level when has articles', function() {
- var article = SummaryPart.create({
- articles: [
- {
- title: 'Test'
- }
- ]
- }, '1');
- expect(article.createChildLevel()).toBe('1.2');
- });
- });
-});
-
-
diff --git a/lib/models/__tests__/templateBlock.js b/lib/models/__tests__/templateBlock.js
deleted file mode 100644
index e5f7666..0000000
--- a/lib/models/__tests__/templateBlock.js
+++ /dev/null
@@ -1,205 +0,0 @@
-var nunjucks = require('nunjucks');
-var Immutable = require('immutable');
-var Promise = require('../../utils/promise');
-
-describe('TemplateBlock', function() {
- var TemplateBlock = require('../templateBlock');
-
- describe('create', function() {
- it('must initialize a simple TemplateBlock from a function', function() {
- var templateBlock = TemplateBlock.create('sayhello', function(block) {
- return {
- body: '<p>Hello, World!</p>',
- parse: true
- };
- });
-
- // Check basic templateBlock properties
- expect(templateBlock.getName()).toBe('sayhello');
- expect(templateBlock.getEndTag()).toBe('endsayhello');
- expect(templateBlock.getBlocks().size).toBe(0);
- expect(templateBlock.getExtensionName()).toBe('BlocksayhelloExtension');
-
- // Check result of applying block
- return Promise()
- .then(function() {
- return templateBlock.applyBlock();
- })
- .then(function(result) {
- expect(result.name).toBe('sayhello');
- expect(result.body).toBe('<p>Hello, World!</p>');
- });
- });
- });
-
- describe('getShortcuts', function() {
- it('must return undefined if no shortcuts', function() {
- var templateBlock = TemplateBlock.create('sayhello', function(block) {
- return {
- body: '<p>Hello, World!</p>',
- parse: true
- };
- });
-
- expect(templateBlock.getShortcuts()).toNotExist();
- });
-
- it('must return complete shortcut', function() {
- var templateBlock = TemplateBlock.create('sayhello', {
- process: function(block) {
- return '<p>Hello, World!</p>';
- },
- shortcuts: {
- parsers: ['markdown'],
- start: '$',
- end: '-'
- }
- });
-
- var shortcut = templateBlock.getShortcuts();
-
- expect(shortcut).toBeDefined();
- expect(shortcut.getStart()).toEqual('$');
- expect(shortcut.getEnd()).toEqual('-');
- expect(shortcut.getStartTag()).toEqual('sayhello');
- expect(shortcut.getEndTag()).toEqual('endsayhello');
- });
- });
-
- describe('toNunjucksExt()', function() {
- it('should replace by block anchor', function() {
- var templateBlock = TemplateBlock.create('sayhello', function(block) {
- return 'Hello';
- });
-
- var blocks = {};
-
- // Create a fresh Nunjucks environment
- var env = new nunjucks.Environment(null, { autoescape: false });
-
- // Add template block to environement
- var Ext = templateBlock.toNunjucksExt({}, blocks);
- env.addExtension(templateBlock.getExtensionName(), new Ext());
-
- // Render a template using the block
- var src = '{% sayhello %}{% endsayhello %}';
- return Promise.nfcall(env.renderString.bind(env), src)
- .then(function(res) {
- blocks = Immutable.fromJS(blocks);
- expect(blocks.size).toBe(1);
-
- var blockId = blocks.keySeq().get(0);
- var block = blocks.get(blockId);
-
- expect(res).toBe('{{-%' + blockId + '%-}}');
- expect(block.get('body')).toBe('Hello');
- expect(block.get('name')).toBe('sayhello');
- });
- });
-
- it('must create a valid nunjucks extension', function() {
- var templateBlock = TemplateBlock.create('sayhello', function(block) {
- return {
- body: '<p>Hello, World!</p>',
- parse: true
- };
- });
-
- // Create a fresh Nunjucks environment
- var env = new nunjucks.Environment(null, { autoescape: false });
-
- // Add template block to environement
- var Ext = templateBlock.toNunjucksExt();
- env.addExtension(templateBlock.getExtensionName(), new Ext());
-
- // Render a template using the block
- var src = '{% sayhello %}{% endsayhello %}';
- return Promise.nfcall(env.renderString.bind(env), src)
- .then(function(res) {
- expect(res).toBe('<p>Hello, World!</p>');
- });
- });
-
- it('must apply block arguments correctly', function() {
- var templateBlock = TemplateBlock.create('sayhello', function(block) {
- return {
- body: '<'+block.kwargs.tag+'>Hello, '+block.kwargs.name+'!</'+block.kwargs.tag+'>',
- parse: true
- };
- });
-
- // Create a fresh Nunjucks environment
- var env = new nunjucks.Environment(null, { autoescape: false });
-
- // Add template block to environement
- var Ext = templateBlock.toNunjucksExt();
- env.addExtension(templateBlock.getExtensionName(), new Ext());
-
- // Render a template using the block
- var src = '{% sayhello name="Samy", tag="p" %}{% endsayhello %}';
- return Promise.nfcall(env.renderString.bind(env), src)
- .then(function(res) {
- expect(res).toBe('<p>Hello, Samy!</p>');
- });
- });
-
- it('must accept an async function', function() {
- var templateBlock = TemplateBlock.create('sayhello', function(block) {
- return Promise()
- .then(function() {
- return {
- body: 'Hello ' + block.body,
- parse: true
- };
- });
- });
-
- // Create a fresh Nunjucks environment
- var env = new nunjucks.Environment(null, { autoescape: false });
-
- // Add template block to environement
- var Ext = templateBlock.toNunjucksExt();
- env.addExtension(templateBlock.getExtensionName(), new Ext());
-
- // Render a template using the block
- var src = '{% sayhello %}Samy{% endsayhello %}';
- return Promise.nfcall(env.renderString.bind(env), src)
- .then(function(res) {
- expect(res).toBe('Hello Samy');
- });
- });
-
- it('must handle nested blocks', function() {
- var templateBlock = new TemplateBlock({
- name: 'yoda',
- blocks: Immutable.List(['start', 'end']),
- process: function(block) {
- var nested = {};
-
- block.blocks.forEach(function(blk) {
- nested[blk.name] = blk.body.trim();
- });
-
- return {
- body: '<p class="yoda">'+nested.end+' '+nested.start+'</p>',
- parse: true
- };
- }
- });
-
- // Create a fresh Nunjucks environment
- var env = new nunjucks.Environment(null, { autoescape: false });
-
- // Add template block to environement
- var Ext = templateBlock.toNunjucksExt();
- env.addExtension(templateBlock.getExtensionName(), new Ext());
-
- // Render a template using the block
- var src = '{% yoda %}{% start %}this sentence should be{% end %}inverted{% endyoda %}';
- return Promise.nfcall(env.renderString.bind(env), src)
- .then(function(res) {
- expect(res).toBe('<p class="yoda">inverted this sentence should be</p>');
- });
- });
- });
-}); \ No newline at end of file
diff --git a/lib/models/__tests__/templateEngine.js b/lib/models/__tests__/templateEngine.js
deleted file mode 100644
index 6f18b18..0000000
--- a/lib/models/__tests__/templateEngine.js
+++ /dev/null
@@ -1,51 +0,0 @@
-
-describe('TemplateBlock', function() {
- var TemplateEngine = require('../templateEngine');
-
- describe('create', function() {
- it('must initialize with a list of filters', function() {
- var engine = TemplateEngine.create({
- filters: {
- hello: function(name) {
- return 'Hello ' + name + '!';
- }
- }
- });
- var env = engine.toNunjucks();
- var res = env.renderString('{{ "Luke"|hello }}');
-
- expect(res).toBe('Hello Luke!');
- });
-
- it('must initialize with a list of globals', function() {
- var engine = TemplateEngine.create({
- globals: {
- hello: function(name) {
- return 'Hello ' + name + '!';
- }
- }
- });
- var env = engine.toNunjucks();
- var res = env.renderString('{{ hello("Luke") }}');
-
- expect(res).toBe('Hello Luke!');
- });
-
- it('must pass context to filters and blocks', function() {
- var engine = TemplateEngine.create({
- filters: {
- hello: function(name) {
- return 'Hello ' + name + ' ' + this.lastName + '!';
- }
- },
- context: {
- lastName: 'Skywalker'
- }
- });
- var env = engine.toNunjucks();
- var res = env.renderString('{{ "Luke"|hello }}');
-
- expect(res).toBe('Hello Luke Skywalker!');
- });
- });
-}); \ No newline at end of file