some helper tests

v1.18.x
barisusakli 8 years ago
parent 04b07e292c
commit 048eb8a320

@ -77,7 +77,6 @@ app.cacheBuster = null;
require(['taskbar', 'helpers', 'forum/pagination'], function (taskbar, helpers, pagination) { require(['taskbar', 'helpers', 'forum/pagination'], function (taskbar, helpers, pagination) {
taskbar.init(); taskbar.init();
// templates.js helpers
helpers.register(); helpers.register();
pagination.init(); pagination.init();

@ -7,7 +7,7 @@
exports = module.exports/* = SemVer*/; exports = module.exports/* = SemVer*/;
} }
var helpers = {}; var helpers = exports;
helpers.displayMenuItem = function (data, index) { helpers.displayMenuItem = function (data, index) {
var item = data.navigation[index]; var item = data.navigation[index];

@ -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, '{&quot;a&quot;:&quot;herp &lt; derp &gt; and &amp; quote \\&quot;&quot;}');
done();
});
it('should escape html', function (done) {
var str = helpers.escape('gdkfhgk < some > and &');
assert.equal(str, 'gdkfhgk &lt; some &gt; and &amp;');
done();
});
});
Loading…
Cancel
Save