summaryrefslogtreecommitdiffstats
path: root/core/js/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-12-01 16:17:28 +0100
committerVincent Petry <pvince81@owncloud.com>2014-12-01 16:20:44 +0100
commitc02ef695217f42dff501e481a50f4669d1cb1f29 (patch)
tree98ef997af355d9fd050645a7ba5c827056c87392 /core/js/tests
parent8db4dd7585aa9daebb32a3f3305f4061b17c316d (diff)
downloadnextcloud-server-c02ef695217f42dff501e481a50f4669d1cb1f29.tar.gz
nextcloud-server-c02ef695217f42dff501e481a50f4669d1cb1f29.zip
Simple Plugin system for Javascript
Diffstat (limited to 'core/js/tests')
-rw-r--r--core/js/tests/specHelper.js3
-rw-r--r--core/js/tests/specs/coreSpec.js31
2 files changed, 34 insertions, 0 deletions
diff --git a/core/js/tests/specHelper.js b/core/js/tests/specHelper.js
index 4111b6763d9..59c2a99645f 100644
--- a/core/js/tests/specHelper.js
+++ b/core/js/tests/specHelper.js
@@ -120,6 +120,9 @@ window.isPhantom = /phantom/i.test(navigator.userAgent);
if (!OC.TestUtil) {
OC.TestUtil = TestUtil;
}
+
+ // reset plugins
+ OC.Plugins._plugins = [];
});
afterEach(function() {
diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js
index 2c5c22905b0..08395f4d4c2 100644
--- a/core/js/tests/specs/coreSpec.js
+++ b/core/js/tests/specs/coreSpec.js
@@ -655,5 +655,36 @@ describe('Core base tests', function() {
]);
});
});
+ describe('Plugins', function() {
+ var plugin;
+
+ beforeEach(function() {
+ plugin = {
+ name: 'Some name',
+ attach: function(obj) {
+ obj.attached = true;
+ },
+
+ detach: function(obj) {
+ obj.attached = false;
+ }
+ };
+ OC.Plugins.register('OC.Test.SomeName', plugin);
+ });
+ it('attach plugin to object', function() {
+ var obj = {something: true};
+ OC.Plugins.attach('OC.Test.SomeName', obj);
+ expect(obj.attached).toEqual(true);
+ OC.Plugins.detach('OC.Test.SomeName', obj);
+ expect(obj.attached).toEqual(false);
+ });
+ it('only call handler for target name', function() {
+ var obj = {something: true};
+ OC.Plugins.attach('OC.Test.SomeOtherName', obj);
+ expect(obj.attached).not.toBeDefined();
+ OC.Plugins.detach('OC.Test.SomeOtherName', obj);
+ expect(obj.attached).not.toBeDefined();
+ });
+ });
});