diff --git a/public/src/app.js b/public/src/app.js index 0006db25d5..85bb5065aa 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -77,7 +77,6 @@ app.cacheBuster = null; require(['taskbar', 'helpers', 'forum/pagination'], function (taskbar, helpers, pagination) { taskbar.init(); - // templates.js helpers helpers.register(); pagination.init(); diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.js index 3035d29fc4..b1ac2e183e 100644 --- a/public/src/modules/helpers.js +++ b/public/src/modules/helpers.js @@ -7,7 +7,7 @@ exports = module.exports/* = SemVer*/; } - var helpers = {}; + var helpers = exports; helpers.displayMenuItem = function (data, index) { var item = data.navigation[index]; diff --git a/test/template-helpers.js b/test/template-helpers.js new file mode 100644 index 0000000000..87502f9e40 --- /dev/null +++ b/test/template-helpers.js @@ -0,0 +1,55 @@ +'use strict'; + +var async = require('async'); +var assert = require('assert'); + +var db = require('./mocks/databasemock'); +var helpers = require('../public/src/modules/helpers'); + +describe('helpers', function () { + + + it('should return false if item doesn\'t exist', function (done) { + var flag = helpers.displayMenuItem({navigation: []}, 0); + assert(!flag); + done(); + }); + + + it('should return false if route is /users and privateUserInfo is on and user is not logged in', function (done) { + var flag = helpers.displayMenuItem({ + navigation: [{route: '/users'}], + privateUserInfo: true, + config: { + loggedIn: false + } + }, 0); + assert(!flag); + done(); + }); + + it('should return false if route is /tags and privateTagListing is on and user is not logged in', function (done) { + var flag = helpers.displayMenuItem({ + navigation: [{route: '/tags'}], + privateTagListing: true, + config: { + loggedIn: false + } + }, 0); + assert(!flag); + done(); + }); + + it('should stringify object', function (done) { + var str = helpers.stringify({a: 'herp < derp > and & quote "'}); + assert.equal(str, '{"a":"herp < derp > and & quote \\""}'); + done(); + }); + + it('should escape html', function (done) { + var str = helpers.escape('gdkfhgk < some > and &'); + assert.equal(str, 'gdkfhgk < some > and &'); + done(); + }); + +});