'use strict'; require('mocha'); var assert = require('assert'); var hbs = require('handlebars').create(); var helpers = require('..'); helpers.html({handlebars: hbs}); var locals = {data: [{aaa: 'AAA', bbb: 'BBB'}, {aaa: 'CCC', bbb: 'DDD'}]}; var actual; describe('html', function() { describe('attr', function() { it('should strip html from a string.', function() { var actual = hbs.compile('')({foo: 'btn'}); assert.equal(actual, '
'); assert.equal(hbs.compile('{{attr}}')(), ''); }); }); describe('css', function() { it('should return an empty string when no context is passed:', function() { assert.equal(hbs.compile('{{{css}}}')(), ''); }); it('should use a path passed as a string', function() { var actual = hbs.compile('{{{css "abc.css"}}}')(); assert.equal(actual, ''); }); it('should use options.assets', function() { var actual = hbs.compile('{{{css "abc.css"}}}')({options: {assets: 'foo'}}); assert.equal(actual, ''); }); it('should ensure that options.assets is a string', function() { var actual = hbs.compile('{{{css "abc.css"}}}')({options: {assets: null}}); assert.equal(actual, ''); }); it('should not use options.assets when passing in an absolute url', function() { var actual = hbs.compile('{{{css "https://abc.com/bar.css"}}}')({options: {assets: 'foo'}}); assert.equal(actual, ''); }); it('should use the `href` attribute on the hash', function() { actual = hbs.compile('{{{css href=""}}}')(); assert.equal(actual, ''); actual = hbs.compile('{{{css href="abc.css"}}}')(); assert.equal(actual, ''); }); it('should create multiple tags from an array passed on the context:', function() { var ctx = {styles: ['a.css', 'bcss', 'c.css'] }; assert.equal(hbs.compile('{{{css styles}}}')(ctx), [ '', '', '' ].join('\n')); }); it('should create a less tag (TODO: only works with array format)', function() { var ctx = {styles: ['a.less'] }; assert.equal(hbs.compile('{{{css styles}}}')(ctx), ''); }); }); describe('js', function() { it('should create an empty script tag', function() { assert.equal(hbs.compile('{{{js}}}')(), ''); }); it('should use a path passed as a string', function() { assert.equal(hbs.compile('{{{js "abc.js"}}}')(), ''); }); it('should use the `src` attribute on the hash', function() { assert.equal(hbs.compile('{{{js src=""}}}')(), ''); assert.equal(hbs.compile('{{{js src="abc.js"}}}')(), ''); }); it('should create multiple tags from an array passed on the context:', function() { var ctx = {scripts: ['a.js', 'bjs', 'c.js'] }; assert.equal(hbs.compile('{{{js scripts}}}')(ctx), [ '', '', '' ].join('\n')); }); it('should create a coffeescript tag (TODO: only works with array format)', function() { var ctx = {scripts: ['a.coffee'] }; assert.equal(hbs.compile('{{{js scripts}}}')(ctx), ''); }); }); describe('sanitize', function() { it('should return an empty string when undefined.', function() { assert.equal(hbs.compile('{{sanitize}}')(), ''); }); it('should strip html from a string.', function() { var actual = hbs.compile('{{sanitize "foo"}}')(); assert.equal(actual, 'foo'); }); }); describe('ul', function() { it('should should return an unordered list', function() { var fn = hbs.compile('{{#ul data class="names"}}{{aaa}} {{bbb}}{{/ul}}'); assert.equal(fn(locals), ''); }); }); describe('ol', function() { it('should should return an ordered list', function() { var fn = hbs.compile('{{#ol data class="names"}}{{aaa}} {{bbb}}{{/ol}}'); assert.equal(fn(locals), '
  1. AAA BBB
  2. \n
  3. CCC DDD
'); }); }); describe('thumbnailImage', function() { describe('{{{thumbnailImage context}}}', function() { it('should return figure with link and caption', function() { var context = { data: { id: 'id', alt: 'Picture of a placeholder', thumbnail: 'http://placehold.it/200x200/0eafff/ffffff.png', size: { width: 200, height: 200 }, full: 'http://placehold.it/600x400/0eafff/ffffff.png', caption: 'My new caption!' } }; var fn = hbs.compile('{{{thumbnailImage data}}}'); var comparison = [ '
', '', 'Picture of a placeholder', '', '
My new caption!
', '
' ].join('\n'); assert.equal(fn(context), comparison); }); it('should return figure with extra class "test"', function() { var source = '{{{thumbnailImage data}}}'; var context = { data: { id: 'id', alt: 'Picture of a placeholder', thumbnail: 'http://placehold.it/200x200/0eafff/ffffff.png', size: { width: 200, height: 200 }, classes: { figure: ['test'] }, full: 'http://placehold.it/600x400/0eafff/ffffff.png', caption: 'My new caption!' } }; var fn = hbs.compile(source); var comparison = [ '
', '', 'Picture of a placeholder', '', '
My new caption!
', '
' ].join('\n'); assert.equal(fn(context), comparison); }); it('should return figure with image that has class "test"', function() { var source = '{{{thumbnailImage data}}}'; var context = { data: { id: 'id', alt: 'Picture of a placeholder', thumbnail: 'http://placehold.it/200x200/0eafff/ffffff.png', size: { width: 200, height: 200 }, full: 'http://placehold.it/600x400/0eafff/ffffff.png', classes: { image: ['test'] }, caption: 'My new caption!' } }; var fn = hbs.compile(source); var comparison = [ '
', '', 'Picture of a placeholder', '', '
My new caption!
', '
' ].join('\n'); assert.equal(fn(context), comparison); }); it('should return figure with link that has class "test"', function() { var source = '{{{thumbnailImage data}}}'; var context = { data: { id: 'id', alt: 'Picture of a placeholder', thumbnail: 'http://placehold.it/200x200/0eafff/ffffff.png', size: { width: 200, height: 200 }, full: 'http://placehold.it/600x400/0eafff/ffffff.png', classes: { link: ['test'] }, caption: 'My new caption!' } }; var fn = hbs.compile(source); var comparison = [ '
', '', 'Picture of a placeholder', '', '
My new caption!
', '
' ].join('\n'); assert.equal(fn(context), comparison); }); it('should return figure without link', function() { var source = '{{{thumbnailImage data}}}'; var context = { data: { id: 'id', alt: 'Picture of a placeholder', thumbnail: 'http://placehold.it/200x200/0eafff/ffffff.png', size: { width: 200, height: 200 }, caption: 'My new caption!' } }; var fn = hbs.compile(source); var comparison = [ '
', 'Picture of a placeholder', '
My new caption!
', '
' ].join('\n'); assert.equal(fn(context), comparison); }); it('should return figure without caption', function() { var source = '{{{thumbnailImage data}}}'; var context = { data: { id: 'id', alt: 'Picture of a placeholder', thumbnail: 'http://placehold.it/200x200/0eafff/ffffff.png', size: { width: 200, height: 200 }, full: 'http://placehold.it/600x400/0eafff/ffffff.png' } }; var fn = hbs.compile(source); var comparison = [ '
', '', 'Picture of a placeholder', '', '
' ].join('\n'); assert.equal(fn(context), comparison); }); }); }); });