|
|
@@ -80,3 +80,71 @@ describe( 'load', function() {
|
|
|
} );
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+describe( 'add', function() {
|
|
|
+ it( 'should add plugins to the collection', function() {
|
|
|
+ var PluginCollection = modules.plugincollection;
|
|
|
+
|
|
|
+ var plugins = new PluginCollection( editor );
|
|
|
+
|
|
|
+ var pluginA = new PluginA();
|
|
|
+ var pluginB = new PluginB();
|
|
|
+
|
|
|
+ // `add()` requires the `name` property to the defined.
|
|
|
+ pluginA.name = 'A';
|
|
|
+ pluginB.name = 'B';
|
|
|
+
|
|
|
+ plugins.add( pluginA );
|
|
|
+ plugins.add( pluginB );
|
|
|
+
|
|
|
+ expect( plugins.length ).to.equal( 2 );
|
|
|
+
|
|
|
+ expect( plugins.get( 0 ) ).to.be.an.instanceof( PluginA );
|
|
|
+ expect( plugins.get( 1 ) ).to.be.an.instanceof( PluginB );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should do nothing if the plugin is already loaded', function() {
|
|
|
+ var PluginCollection = modules.plugincollection;
|
|
|
+
|
|
|
+ var plugins = new PluginCollection( editor );
|
|
|
+
|
|
|
+ return plugins.load( 'A,B' )
|
|
|
+ .then( function() {
|
|
|
+ // Check length before `add()`.
|
|
|
+ expect( plugins.length ).to.equal( 2 );
|
|
|
+
|
|
|
+ var pluginA = new PluginA();
|
|
|
+ pluginA.name = 'A';
|
|
|
+
|
|
|
+ plugins.add( pluginA );
|
|
|
+
|
|
|
+ // Length should not change after `add()`.
|
|
|
+ expect( plugins.length ).to.equal( 2 );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+} );
|
|
|
+
|
|
|
+describe( 'get', function() {
|
|
|
+ it( 'should get plugin by name', function() {
|
|
|
+ var PluginCollection = modules.plugincollection;
|
|
|
+
|
|
|
+ var plugins = new PluginCollection( editor );
|
|
|
+
|
|
|
+ return plugins.load( 'A,B' )
|
|
|
+ .then( function() {
|
|
|
+ expect( plugins.get( 'A' ) ).to.be.an.instanceof( PluginA );
|
|
|
+ expect( plugins.get( 'B' ) ).to.be.an.instanceof( PluginB );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should return undefined for non existing plugin', function() {
|
|
|
+ var PluginCollection = modules.plugincollection;
|
|
|
+
|
|
|
+ var plugins = new PluginCollection( editor );
|
|
|
+
|
|
|
+ return plugins.load( 'A,B' )
|
|
|
+ .then( function() {
|
|
|
+ expect( plugins.get( 'C' ) ).to.be.an( 'undefined' );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+} );
|