const assert = require('assert'); const hbs = require('handlebars').create(); const helpers = require('..'); helpers.html({ handlebars: hbs }); const locals = {data: [{aaa: 'AAA', bbb: 'BBB'}, {aaa: 'CCC', bbb: 'DDD'}]}; let actual; describe('html', function() { describe('attr', function() { it('should strip html from a string.', function() { const 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() { const actual = hbs.compile('{{{css "abc.css"}}}')(); assert.equal(actual, ''); }); it('should use options.assets', function() { const actual = hbs.compile('{{{css "abc.css"}}}')({options: {assets: 'foo'}}); assert.equal(actual, ''); }); it('should ensure that options.assets is a string', function() { const 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() { const 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() { const 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() { const ctx = {styles: ['a.less'] }; assert.equal(hbs.compile('{{{css styles}}}')(ctx), ''); }); }); describe('ul', function() { it('should should return an unordered list', function() { const 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() { const 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() { const 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!' } }; const fn = hbs.compile('{{{thumbnailImage data}}}'); const comparison = [ '
', '', 'Picture of a placeholder', '', '
My new caption!
', '
' ].join('\n'); assert.equal(fn(context), comparison); }); it('should return figure with extra class "test"', function() { const source = '{{{thumbnailImage data}}}'; const 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!' } }; const fn = hbs.compile(source); const 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() { const source = '{{{thumbnailImage data}}}'; const 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!' } }; const fn = hbs.compile(source); const 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() { const source = '{{{thumbnailImage data}}}'; const 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!' } }; const fn = hbs.compile(source); const comparison = [ '
', '', 'Picture of a placeholder', '', '
My new caption!
', '
' ].join('\n'); assert.equal(fn(context), comparison); }); it('should return figure without link', function() { const source = '{{{thumbnailImage data}}}'; const 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!' } }; const fn = hbs.compile(source); const comparison = [ '
', 'Picture of a placeholder', '
My new caption!
', '
' ].join('\n'); assert.equal(fn(context), comparison); }); it('should return figure without caption', function() { const source = '{{{thumbnailImage data}}}'; const 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' } }; const fn = hbs.compile(source); const comparison = [ '
', '', 'Picture of a placeholder', '', '
' ].join('\n'); assert.equal(fn(context), comparison); }); }); }); });