summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/config.js49
-rw-r--r--test/glossary.js4
-rw-r--r--test/langs.js2
-rw-r--r--test/node_modules/gitbook-plugin-test-hooks/index.js16
-rw-r--r--test/node_modules/gitbook-plugin-test-hooks/package.json7
-rw-r--r--test/page.js6
-rw-r--r--test/plugins.js16
-rw-r--r--test/readme.js2
8 files changed, 92 insertions, 10 deletions
diff --git a/test/config.js b/test/config.js
index 7a96a5c..be28fc9 100644
--- a/test/config.js
+++ b/test/config.js
@@ -46,7 +46,7 @@ describe('Configuration', function() {
return mock.setupDefaultBook()
.then(function(_book) {
book = _book;
- return book.prepareConfig();
+ return book.config.load();
});
});
@@ -64,7 +64,7 @@ describe('Configuration', function() {
})
.then(function(_book) {
book = _book;
- return book.prepareConfig();
+ return book.config.load();
});
});
@@ -82,7 +82,7 @@ describe('Configuration', function() {
})
.then(function(_book) {
book = _book;
- return book.prepareConfig();
+ return book.config.load();
});
});
@@ -90,5 +90,48 @@ describe('Configuration', function() {
book.config.get('title', '').should.equal('Hello World');
});
});
+
+ describe('Multilingual', function() {
+ var book;
+
+ before(function() {
+ return mock.setupDefaultBook({
+ 'book.json': {
+ title: 'Hello World',
+ pluginsConfig: {
+ 'test': {
+ 'hello': true
+ }
+ }
+ },
+ 'LANGS.md': '# Languages\n\n'
+ + '* [en](./en)\n'
+ + '* [fr](./fr)\n\n',
+ 'en/README.md': '# Hello',
+ 'fr/README.md': '# Bonjour',
+ 'en/book.json': { description: 'In english' },
+ 'fr/book.json': { description: 'En francais' }
+ })
+ .then(function(_book) {
+ book = _book;
+ return book.parse();
+ });
+ });
+
+ it('should correctly extend configuration', function() {
+ book.config.get('title', '').should.equal('Hello World');
+ book.config.get('description', '').should.equal('');
+
+ var en = book.books[0];
+ en.config.get('title', '').should.equal('Hello World');
+ en.config.get('description', '').should.equal('In english');
+ en.config.get('pluginsConfig.test.hello').should.equal(true);
+
+ var fr = book.books[1];
+ fr.config.get('title', '').should.equal('Hello World');
+ fr.config.get('description', '').should.equal('En francais');
+ fr.config.get('pluginsConfig.test.hello').should.equal(true);
+ });
+ });
});
diff --git a/test/glossary.js b/test/glossary.js
index e1ba82a..d6d1af6 100644
--- a/test/glossary.js
+++ b/test/glossary.js
@@ -7,7 +7,7 @@ describe('Glossary', function() {
'GLOSSARY.md': ''
})
.then(function(book) {
- return book.prepareConfig()
+ return book.config.load()
.then(function() {
return book.glossary.load();
@@ -27,7 +27,7 @@ describe('Glossary', function() {
})
.then(function(_book) {
book = _book;
- return book.prepareConfig();
+ return book.config.load();
})
.then(function() {
return book.glossary.load();
diff --git a/test/langs.js b/test/langs.js
index dbde992..91dbd5a 100644
--- a/test/langs.js
+++ b/test/langs.js
@@ -6,7 +6,7 @@ describe('Langs', function() {
'LANGS.md': ''
})
.then(function(book) {
- return book.prepareConfig()
+ return book.config.load()
.then(function() {
return book.langs.load();
diff --git a/test/node_modules/gitbook-plugin-test-hooks/index.js b/test/node_modules/gitbook-plugin-test-hooks/index.js
new file mode 100644
index 0000000..c0666ca
--- /dev/null
+++ b/test/node_modules/gitbook-plugin-test-hooks/index.js
@@ -0,0 +1,16 @@
+var should = require('should');
+
+module.exports = {
+ hooks: {
+ 'init': function() {
+ global._hooks = [];
+ global._hooks.push('init');
+ },
+ 'finish': function() {
+ global._hooks.push('finish');
+ },
+ 'finish:before': function() {
+ global._hooks.push('finish:before');
+ }
+ }
+};
diff --git a/test/node_modules/gitbook-plugin-test-hooks/package.json b/test/node_modules/gitbook-plugin-test-hooks/package.json
new file mode 100644
index 0000000..adb12a8
--- /dev/null
+++ b/test/node_modules/gitbook-plugin-test-hooks/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "gitbook-plugin-test-hooks",
+ "version": "1.0.0",
+ "engines": {
+ "gitbook": "*"
+ }
+} \ No newline at end of file
diff --git a/test/page.js b/test/page.js
index 37acc95..f11d55e 100644
--- a/test/page.js
+++ b/test/page.js
@@ -32,7 +32,7 @@ describe('Page', function() {
'variables/page/next.md': '{{ page.next.title }} {{ page.next.path }}',
'variables/page/dir/ltr.md': 'This is english: {{ page.dir }}',
'variables/page/dir/rtl.md': 'بسيطة {{ page.dir }}',
- 'variables/book/title.md': '{{ book.title}}',
+ 'variables/config/title.md': '{{ config.title}}',
'GLOSSARY.md': '# Glossary\n\n\n## abracadabra\n\nthis is the description'
}, [
@@ -318,8 +318,8 @@ describe('Page', function() {
.should.be.fulfilledWith('<p>Test Variables variables/page/title.md</p>\n');
});
- it('should set book.title', function() {
- var page = book.addPage('variables/book/title.md');
+ it('should set config.title', function() {
+ var page = book.addPage('variables/config/title.md');
return page.toHTML(output)
.should.be.fulfilledWith('<p>Hello World</p>\n');
});
diff --git a/test/plugins.js b/test/plugins.js
index 172e00c..4d9cdf1 100644
--- a/test/plugins.js
+++ b/test/plugins.js
@@ -175,5 +175,21 @@ describe('Plugins', function() {
blocks.testContext.process({ body: 'Hello' });
});
});
+
+ describe('Hooks', function() {
+ var plugin;
+
+ before(function() {
+ plugin = new BookPlugin(book, 'test-hooks');
+ return plugin.load(PLUGINS_ROOT);
+ });
+
+ it('can call a hook', function() {
+ return plugin.hook('init')
+ .then(function() {
+ global._hooks.should.deepEqual(['init']);
+ });
+ });
+ });
});
diff --git a/test/readme.js b/test/readme.js
index 16aa81a..0cf66ff 100644
--- a/test/readme.js
+++ b/test/readme.js
@@ -6,7 +6,7 @@ describe('Readme', function() {
'README.md': ''
})
.then(function(book) {
- return book.prepareConfig()
+ return book.config.load()
.then(function() {
return book.readme.load();