summaryrefslogtreecommitdiffstats
path: root/lib/models
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-05-04 20:18:48 +0200
committerSamy Pesse <samypesse@gmail.com>2016-05-04 20:18:48 +0200
commitc621380b664bcbef087df571b662e7a34e098168 (patch)
tree9a416eb1399b5474c879d67fbd0ff5d6811eb25a /lib/models
parentc4b54033cefe54f2c7fda92b8765ed500178ea74 (diff)
downloadgitbook-c621380b664bcbef087df571b662e7a34e098168.zip
gitbook-c621380b664bcbef087df571b662e7a34e098168.tar.gz
gitbook-c621380b664bcbef087df571b662e7a34e098168.tar.bz2
Add tests for replaceShortcuts
Diffstat (limited to 'lib/models')
-rw-r--r--lib/models/__tests__/templateBlock.js32
-rw-r--r--lib/models/templateBlock.js8
-rw-r--r--lib/models/templateShortcut.js2
3 files changed, 36 insertions, 6 deletions
diff --git a/lib/models/__tests__/templateBlock.js b/lib/models/__tests__/templateBlock.js
index b8c426e..597b672 100644
--- a/lib/models/__tests__/templateBlock.js
+++ b/lib/models/__tests__/templateBlock.js
@@ -17,7 +17,6 @@ describe('TemplateBlock', function() {
expect(templateBlock.getParse()).toBeTruthy();
expect(templateBlock.getEndTag()).toBe('endsayhello');
expect(templateBlock.getBlocks().size).toBe(0);
- expect(templateBlock.getShortcuts().size).toBe(0);
expect(templateBlock.getExtensionName()).toBe('BlocksayhelloExtension');
// Check result of applying block
@@ -32,6 +31,37 @@ describe('TemplateBlock', function() {
});
});
+ describe('getShortcuts', function() {
+ it('must return undefined if no shortcuts', function() {
+ var templateBlock = TemplateBlock.create('sayhello', function(block) {
+ return '<p>Hello, World!</p>';
+ });
+
+ expect(templateBlock.getShortcuts()).not.toBeDefined();
+ });
+
+ 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() {
pit('must create a valid nunjucks extension', function() {
var templateBlock = TemplateBlock.create('sayhello', function(block) {
diff --git a/lib/models/templateBlock.js b/lib/models/templateBlock.js
index 76aeb55..2ec1328 100644
--- a/lib/models/templateBlock.js
+++ b/lib/models/templateBlock.js
@@ -304,11 +304,9 @@ TemplateBlock.create = function(blockName, block) {
});
}
- block = block.merge({
- name: blockName
- });
-
- return new TemplateBlock(block);
+ block = new TemplateBlock(block);
+ block = block.set('name', blockName);
+ return block;
};
/**
diff --git a/lib/models/templateShortcut.js b/lib/models/templateShortcut.js
index 672c7ba..309fa6d 100644
--- a/lib/models/templateShortcut.js
+++ b/lib/models/templateShortcut.js
@@ -59,6 +59,8 @@ TemplateShortcut.prototype.acceptParser = function(parser) {
@return {TemplateShortcut}
*/
TemplateShortcut.createForBlock = function(block, details) {
+ details = Immutable.fromJS(details);
+
return new TemplateShortcut({
parsers: details.get('parsers'),
start: details.get('start'),