From 5e7fb4eeb240c9732051a8f0af8ff51972879f79 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 18 Nov 2016 14:43:19 +0300 Subject: [PATCH] widget tests --- src/socket.io/admin.js | 2 +- test/controllers.js | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index e59e15d55c..8240dd8b36 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -120,7 +120,7 @@ SocketAdmin.plugins.upgrade = function (socket, data, callback) { }; SocketAdmin.widgets.set = function (socket, data, callback) { - if(!data) { + if (!data) { return callback(new Error('[[error:invalid-data]]')); } diff --git a/test/controllers.js b/test/controllers.js index bdaa1e908d..fb80b5a3dc 100644 --- a/test/controllers.js +++ b/test/controllers.js @@ -558,7 +558,59 @@ describe('Controllers', function () { }); }); }); + }); + + describe('widgets', function () { + var widgets = require('../src/widgets'); + + before(function (done) { + async.waterfall([ + function (next) { + widgets.reset(next); + }, + function (next) { + var data = { + template: 'categories.tpl', + location: 'sidebar', + widgets: [ + { + widget: 'html', + data: [ { + widget: 'html', + data: { + html: 'test', + title: '', + container: '' + } + } ] + } + ] + }; + + widgets.setArea(data, next); + } + ], done); + }); + it('should return {} if there is no template or locations', function (done) { + request(nconf.get('url') + '/api/widgets/render', {json: true}, function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + assert.equal(Object.keys(body), 0); + done(); + }); + }); + + it('should render templates', function (done) { + var url = nconf.get('url') + '/api/widgets/render?template=categories.tpl&url=&isMobile=false&locations%5B%5D=sidebar&locations%5B%5D=footer&locations%5B%5D=header'; + request(url, {json: true}, function (err, res, body) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + assert(body); + done(); + }); + }); });