diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js index 32cda3b7ac..ae7493aedc 100644 --- a/public/src/modules/helpers.common.js +++ b/public/src/modules/helpers.common.js @@ -383,7 +383,7 @@ module.exports = function (utils, Benchpress, relative_path) { `; }); - return html; + return html.join(''); } function register() { diff --git a/test/template-helpers.js b/test/template-helpers.js index 76346dbf13..8e95e66c8c 100644 --- a/test/template-helpers.js +++ b/test/template-helpers.js @@ -52,6 +52,17 @@ describe('helpers', () => { done(); }); + it('should return true if route is visible', (done) => { + const flag = helpers.displayMenuItem({ + navigation: [{ route: '/recent' }], + user: { + privileges: {}, + }, + }, 0); + assert(flag); + done(); + }); + it('should stringify object', (done) => { const str = helpers.stringify({ a: 'herp < derp > and & quote "' }); assert.equal(str, '{"a":"herp < derp > and & quote \\""}'); @@ -64,7 +75,57 @@ describe('helpers', () => { done(); }); + it('should build category icon', (done) => { + assert.strictEqual( + helpers.buildCategoryIcon({ + bgColor: '#ff0000', + color: '#00ff00', + backgroundImage: '/assets/uploads/image.png', + imageClass: 'auto', + }, 16, 'rounded-circle'), + '' + ); + assert.strictEqual( + helpers.buildCategoryIcon({ + bgColor: '#ff0000', + color: '#00ff00', + backgroundImage: '/assets/uploads/image.png', + imageClass: 'auto', + icon: 'fa-book', + }, 16, 'rounded-circle'), + '' + ); + done(); + }); + + it('should build category label', (done) => { + assert.strictEqual( + helpers.buildCategoryLabel({ + bgColor: '#ff0000', + color: '#00ff00', + backgroundImage: '/assets/uploads/image.png', + imageClass: 'auto', + name: 'Category 1', + }, 'a', ''), + `\n\t\t\t\n\t\t\tCategory 1\n\t\t` + ); + assert.strictEqual( + helpers.buildCategoryLabel({ + bgColor: '#ff0000', + color: '#00ff00', + backgroundImage: '/assets/uploads/image.png', + imageClass: 'auto', + name: 'Category 1', + icon: 'fa-book', + }, 'span', 'rounded-1'), + `\n\t\t\t\n\t\t\tCategory 1\n\t\t`, + ); + done(); + }); + it('should return empty string if category is falsy', (done) => { + assert.equal(helpers.buildCategoryIcon(null), ''); + assert.equal(helpers.buildCategoryLabel(null), ''); assert.equal(helpers.generateCategoryBackground(null), ''); done(); }); @@ -251,4 +312,34 @@ describe('helpers', () => { assert.equal(html, ''); done(); }); + + it('should generate replied to or wrote based on toPid', (done) => { + const now = Date.now(); + const iso = new Date().toISOString(); + let post = { pid: 2, toPid: 1, timestamp: now, timestampISO: iso, parent: { displayname: 'baris' } }; + let str = helpers.generateWroteReplied(post, 1); + assert.strictEqual(str, `[[topic:replied-to-user-ago, 1, /post/1, baris, /post/2, ${iso}]]`); + + post = { pid: 2, toPid: 1, timestamp: now, timestampISO: iso, parent: { displayname: 'baris' } }; + str = helpers.generateWroteReplied(post, -1); + assert.strictEqual(str, `[[topic:replied-to-user-on, 1, /post/1, baris, /post/2, ${iso}]]`); + + post = { pid: 2, timestamp: now, timestampISO: iso, parent: { displayname: 'baris' } }; + str = helpers.generateWroteReplied(post, 1); + assert.strictEqual(str, `[[topic:wrote-ago, /post/2, ${iso}]]`); + + str = helpers.generateWroteReplied(post, -1); + assert.strictEqual(str, `[[topic:wrote-on, /post/2, ${iso}]]`); + + done(); + }); + + it('should generate placeholder wave', (done) => { + const items = [2, 'divider', 3]; + const str = helpers.generatePlaceholderWave(items); + assert(str.includes('dropdown-divider')); + assert(str.includes('col-2')); + assert(str.includes('col-3')); + done(); + }); });