Ghost/core/test/unit/plugins_spec.js

121 lines
3.8 KiB
JavaScript
Raw Normal View History

2013-08-21 00:28:19 +04:00
/*globals describe, beforeEach, before, it*/
var _ = require("underscore"),
when = require('when'),
should = require('should'),
sinon = require('sinon'),
errors = require('../../server/errorHandling'),
helpers = require('./helpers'),
plugins = require('../../server/plugins'),
GhostPlugin = plugins.GhostPlugin,
2013-08-21 00:28:19 +04:00
loader = require('../../server/plugins/loader');
describe('Plugins', function () {
before(function (done) {
helpers.clearData().then(function () {
done();
}, done);
});
beforeEach(function (done) {
this.timeout(5000);
helpers.initData().then(function () {
done();
}, done);
});
afterEach(function (done) {
helpers.clearData().then(function () {
done();
}, done);
});
describe('GhostPlugin Class', function () {
should.exist(GhostPlugin);
it('sets app instance', function () {
var fakeGhost = {fake: true},
plugin = new GhostPlugin(fakeGhost);
plugin.app.should.equal(fakeGhost);
});
it('has default install, uninstall, activate and deactivate methods', function () {
var fakeGhost = {fake: true},
plugin = new GhostPlugin(fakeGhost);
_.isFunction(plugin.install).should.equal(true);
_.isFunction(plugin.uninstall).should.equal(true);
_.isFunction(plugin.activate).should.equal(true);
_.isFunction(plugin.deactivate).should.equal(true);
});
});
describe('loader', function () {
// TODO: These depend heavily on the FancyFirstChar plugin being present.
it('can load FancyFirstChar by name and unload', function (done) {
var fancyPlugin = require("../../../content/plugins/FancyFirstChar"),
fakeGhost = {
registerFilter: function () { return; },
unregisterFilter: function () { return; }
},
installMock = sinon.stub(fancyPlugin, "install"),
uninstallMock = sinon.stub(fancyPlugin, "uninstall"),
registerMock = sinon.stub(fakeGhost, "registerFilter"),
unregisterMock = sinon.stub(fakeGhost, "unregisterFilter");
loader.installPluginByName("FancyFirstChar", fakeGhost).then(function (loadedPlugin) {
2013-08-21 00:28:19 +04:00
should.exist(loadedPlugin);
2013-08-21 00:28:19 +04:00
installMock.called.should.equal(true);
loadedPlugin.activate(fakeGhost);
2013-08-21 00:28:19 +04:00
// Registers the filter
registerMock.called.should.equal(true);
loadedPlugin.deactivate(fakeGhost);
// Unregisters the filter
unregisterMock.called.should.equal(true);
loadedPlugin.uninstall(fakeGhost);
done();
}, done);
});
});
it("can initialize an array of plugins", function (done) {
var fakeGhost = {
registerFilter: function () { return; },
unregisterFilter: function () { return; }
},
installSpy = sinon.spy(loader, "installPluginByName"),
activateSpy = sinon.spy(loader, "activatePluginByName");
plugins.init(fakeGhost, ["FancyFirstChar"]).then(function (loadedPlugins) {
should.exist(loadedPlugins);
should.exist(loadedPlugins["FancyFirstChar"]);
installSpy.called.should.equal(true);
activateSpy.called.should.equal(true);
var api = require("../../server/api");
return api.settings.read("installedPlugins").then(function (setting) {
should.exist(setting);
2013-08-21 00:28:19 +04:00
setting.value.should.equal('["FancyFirstChar"]');
done();
});
}, done);
});
});