|
@@ -6,155 +6,157 @@
|
|
|
import Editor from 'ckeditor5/core/editor/editor.js';
|
|
import Editor from 'ckeditor5/core/editor/editor.js';
|
|
|
import Command from 'ckeditor5/core/command/command.js';
|
|
import Command from 'ckeditor5/core/command/command.js';
|
|
|
|
|
|
|
|
-let editor, command;
|
|
|
|
|
|
|
+describe( 'Command', () => {
|
|
|
|
|
+ let editor, command;
|
|
|
|
|
|
|
|
-class CommandWithSchema extends Command {
|
|
|
|
|
- constructor( editor, schemaValid ) {
|
|
|
|
|
- super( editor );
|
|
|
|
|
|
|
+ class CommandWithSchema extends Command {
|
|
|
|
|
+ constructor( editor, schemaValid ) {
|
|
|
|
|
+ super( editor );
|
|
|
|
|
|
|
|
- this.schemaValid = schemaValid;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.schemaValid = schemaValid;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- _checkEnabled() {
|
|
|
|
|
- return this.schemaValid;
|
|
|
|
|
|
|
+ _checkEnabled() {
|
|
|
|
|
+ return this.schemaValid;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-beforeEach( () => {
|
|
|
|
|
- editor = new Editor();
|
|
|
|
|
- command = new Command( editor );
|
|
|
|
|
-} );
|
|
|
|
|
-
|
|
|
|
|
-afterEach( () => {
|
|
|
|
|
- // Might be redundant if editor destroys the commands.
|
|
|
|
|
- command.destroy();
|
|
|
|
|
- editor.destroy();
|
|
|
|
|
-} );
|
|
|
|
|
|
|
|
|
|
-describe( 'constructor()', () => {
|
|
|
|
|
- it( 'should create a new command instance, that is enabled and bound to given editor', () => {
|
|
|
|
|
- expect( command ).to.have.property( 'editor' ).equal( editor );
|
|
|
|
|
- expect( command.isEnabled ).to.be.true;
|
|
|
|
|
|
|
+ beforeEach( () => {
|
|
|
|
|
+ editor = new Editor();
|
|
|
|
|
+ command = new Command( editor );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'Command should have _doExecute method', () => {
|
|
|
|
|
- expect( () => {
|
|
|
|
|
- command._doExecute();
|
|
|
|
|
- } ).not.to.throw;
|
|
|
|
|
|
|
+ afterEach( () => {
|
|
|
|
|
+ // Might be redundant if editor destroys the commands.
|
|
|
|
|
+ command.destroy();
|
|
|
|
|
+ editor.destroy();
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should add listener to its refreshState event if checkSchema method is present', () => {
|
|
|
|
|
- expect( command._checkEnabled ).to.be.undefined;
|
|
|
|
|
|
|
+ describe( 'constructor()', () => {
|
|
|
|
|
+ it( 'should create a new command instance, that is enabled and bound to given editor', () => {
|
|
|
|
|
+ expect( command ).to.have.property( 'editor' ).equal( editor );
|
|
|
|
|
+ expect( command.isEnabled ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- command._checkEnabled = sinon.spy();
|
|
|
|
|
- command.refreshState();
|
|
|
|
|
|
|
+ it( 'Command should have _doExecute method', () => {
|
|
|
|
|
+ expect( () => {
|
|
|
|
|
+ command._doExecute();
|
|
|
|
|
+ } ).not.to.throw;
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- expect( command._checkEnabled.called ).to.be.false;
|
|
|
|
|
|
|
+ it( 'should add listener to its refreshState event if checkSchema method is present', () => {
|
|
|
|
|
+ expect( command._checkEnabled ).to.be.undefined;
|
|
|
|
|
|
|
|
- let newCommand = new CommandWithSchema( editor, true );
|
|
|
|
|
- sinon.spy( newCommand, '_checkEnabled' );
|
|
|
|
|
|
|
+ command._checkEnabled = sinon.spy();
|
|
|
|
|
+ command.refreshState();
|
|
|
|
|
|
|
|
- newCommand.refreshState();
|
|
|
|
|
|
|
+ expect( command._checkEnabled.called ).to.be.false;
|
|
|
|
|
|
|
|
- expect( newCommand._checkEnabled.calledOnce ).to.be.true;
|
|
|
|
|
- } );
|
|
|
|
|
-} );
|
|
|
|
|
-
|
|
|
|
|
-describe( 'destroy', () => {
|
|
|
|
|
- it( 'should stop listening', () => {
|
|
|
|
|
- sinon.spy( command, 'stopListening' );
|
|
|
|
|
|
|
+ let newCommand = new CommandWithSchema( editor, true );
|
|
|
|
|
+ sinon.spy( newCommand, '_checkEnabled' );
|
|
|
|
|
|
|
|
- command.destroy();
|
|
|
|
|
|
|
+ newCommand.refreshState();
|
|
|
|
|
|
|
|
- expect( command.stopListening.calledOnce ).to.be.true;
|
|
|
|
|
|
|
+ expect( newCommand._checkEnabled.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
-} );
|
|
|
|
|
|
|
|
|
|
-describe( 'refreshState', () => {
|
|
|
|
|
- it( 'should fire refreshState event', () => {
|
|
|
|
|
- let spy = sinon.spy();
|
|
|
|
|
|
|
+ describe( 'destroy', () => {
|
|
|
|
|
+ it( 'should stop listening', () => {
|
|
|
|
|
+ sinon.spy( command, 'stopListening' );
|
|
|
|
|
|
|
|
- command.on( 'refreshState', spy );
|
|
|
|
|
- command.refreshState();
|
|
|
|
|
|
|
+ command.destroy();
|
|
|
|
|
|
|
|
- expect( spy.called ).to.be.true;
|
|
|
|
|
|
|
+ expect( command.stopListening.calledOnce ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should set isEnabled property to the value passed by object-reference', () => {
|
|
|
|
|
- command.on( 'refreshState', ( evt, data ) => {
|
|
|
|
|
- data.isEnabled = true;
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ describe( 'refreshState', () => {
|
|
|
|
|
+ it( 'should fire refreshState event', () => {
|
|
|
|
|
+ let spy = sinon.spy();
|
|
|
|
|
|
|
|
- expect( command.isEnabled ).to.be.true;
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ command.on( 'refreshState', spy );
|
|
|
|
|
+ command.refreshState();
|
|
|
|
|
|
|
|
- it( 'should set isEnabled to false if _checkEnabled returns false', () => {
|
|
|
|
|
- let disabledCommand = new CommandWithSchema( editor, false );
|
|
|
|
|
|
|
+ expect( spy.called ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- disabledCommand.refreshState();
|
|
|
|
|
|
|
+ it( 'should set isEnabled property to the value passed by object-reference', () => {
|
|
|
|
|
+ command.on( 'refreshState', ( evt, data ) => {
|
|
|
|
|
+ data.isEnabled = true;
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- expect( disabledCommand.isEnabled ).to.be.false;
|
|
|
|
|
- } );
|
|
|
|
|
-} );
|
|
|
|
|
|
|
+ expect( command.isEnabled ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should set isEnabled to false if _checkEnabled returns false', () => {
|
|
|
|
|
+ let disabledCommand = new CommandWithSchema( editor, false );
|
|
|
|
|
|
|
|
-describe( 'disable', () => {
|
|
|
|
|
- it( 'should make command disabled', () => {
|
|
|
|
|
- command._disable();
|
|
|
|
|
|
|
+ disabledCommand.refreshState();
|
|
|
|
|
|
|
|
- expect( command.isEnabled ).to.be.false;
|
|
|
|
|
|
|
+ expect( disabledCommand.isEnabled ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should not make command disabled if there is a high-priority listener forcing command to be enabled', () => {
|
|
|
|
|
- command.on( 'refreshState', ( evt ) => {
|
|
|
|
|
- evt.stop();
|
|
|
|
|
|
|
+ describe( 'disable', () => {
|
|
|
|
|
+ it( 'should make command disabled', () => {
|
|
|
|
|
+ command._disable();
|
|
|
|
|
|
|
|
- return true;
|
|
|
|
|
- }, command, 1 );
|
|
|
|
|
|
|
+ expect( command.isEnabled ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- command._disable();
|
|
|
|
|
|
|
+ it( 'should not make command disabled if there is a high-priority listener forcing command to be enabled', () => {
|
|
|
|
|
+ command.on( 'refreshState', ( evt ) => {
|
|
|
|
|
+ evt.stop();
|
|
|
|
|
|
|
|
- expect( command.isEnabled ).to.be.true;
|
|
|
|
|
- } );
|
|
|
|
|
-} );
|
|
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }, command, 1 );
|
|
|
|
|
|
|
|
-describe( 'enable', () => {
|
|
|
|
|
- it( 'should make command enabled if it was previously disabled by disable()', () => {
|
|
|
|
|
- command._disable();
|
|
|
|
|
- command._enable();
|
|
|
|
|
|
|
+ command._disable();
|
|
|
|
|
|
|
|
- expect( command.isEnabled ).to.be.true;
|
|
|
|
|
|
|
+ expect( command.isEnabled ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should not make command enabled if there are other listeners disabling it', () => {
|
|
|
|
|
- command._disable();
|
|
|
|
|
|
|
+ describe( 'enable', () => {
|
|
|
|
|
+ it( 'should make command enabled if it was previously disabled by disable()', () => {
|
|
|
|
|
+ command._disable();
|
|
|
|
|
+ command._enable();
|
|
|
|
|
|
|
|
- command.on( 'refreshState', ( evt, data ) => {
|
|
|
|
|
- data.isEnabled = false;
|
|
|
|
|
|
|
+ expect( command.isEnabled ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- command.refreshState();
|
|
|
|
|
- command._enable();
|
|
|
|
|
|
|
+ it( 'should not make command enabled if there are other listeners disabling it', () => {
|
|
|
|
|
+ command._disable();
|
|
|
|
|
+
|
|
|
|
|
+ command.on( 'refreshState', ( evt, data ) => {
|
|
|
|
|
+ data.isEnabled = false;
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- expect( command.isEnabled ).to.be.false;
|
|
|
|
|
|
|
+ command.refreshState();
|
|
|
|
|
+ command._enable();
|
|
|
|
|
+
|
|
|
|
|
+ expect( command.isEnabled ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
-} );
|
|
|
|
|
|
|
|
|
|
-describe( '_execute', () => {
|
|
|
|
|
- it( 'should not execute command if it is disabled', () => {
|
|
|
|
|
- command._disable();
|
|
|
|
|
|
|
+ describe( '_execute', () => {
|
|
|
|
|
+ it( 'should not execute command if it is disabled', () => {
|
|
|
|
|
+ command._disable();
|
|
|
|
|
|
|
|
- sinon.spy( command, '_doExecute' );
|
|
|
|
|
|
|
+ sinon.spy( command, '_doExecute' );
|
|
|
|
|
|
|
|
- command._execute();
|
|
|
|
|
|
|
+ command._execute();
|
|
|
|
|
|
|
|
- expect( command._doExecute.called ).to.be.false;
|
|
|
|
|
- } );
|
|
|
|
|
|
|
+ expect( command._doExecute.called ).to.be.false;
|
|
|
|
|
+ } );
|
|
|
|
|
|
|
|
- it( 'should execute command if it is enabled', () => {
|
|
|
|
|
- sinon.spy( command, '_doExecute' );
|
|
|
|
|
|
|
+ it( 'should execute command if it is enabled', () => {
|
|
|
|
|
+ sinon.spy( command, '_doExecute' );
|
|
|
|
|
|
|
|
- command._execute();
|
|
|
|
|
|
|
+ command._execute();
|
|
|
|
|
|
|
|
- expect( command._doExecute.called ).to.be.true;
|
|
|
|
|
|
|
+ expect( command._doExecute.called ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|