8
0

command.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Command from '../src/command';
  6. import ModelTestEditor from './_utils/modeltesteditor';
  7. class SomeCommand extends Command {
  8. execute() {}
  9. refresh() {}
  10. }
  11. describe( 'Command', () => {
  12. let editor, command;
  13. beforeEach( () => {
  14. return ModelTestEditor
  15. .create()
  16. .then( newEditor => {
  17. editor = newEditor;
  18. command = new SomeCommand( editor );
  19. } );
  20. } );
  21. afterEach( () => {
  22. command.destroy();
  23. return editor.destroy();
  24. } );
  25. describe( 'constructor()', () => {
  26. it( 'sets the editor property', () => {
  27. expect( command.editor ).to.equal( editor );
  28. } );
  29. it( 'sets the state properties', () => {
  30. expect( command.value ).to.be.null;
  31. expect( command.isEnabled ).to.be.false;
  32. } );
  33. it( 'adds a listener which refreshed the command on editor.document#changesDone', () => {
  34. sinon.spy( command, 'refresh' );
  35. editor.document.fire( 'changesDone' );
  36. expect( command.refresh.calledOnce ).to.be.true;
  37. } );
  38. } );
  39. describe( 'value', () => {
  40. it( 'fires change event', () => {
  41. const spy = sinon.spy();
  42. command.on( 'change:value', spy );
  43. command.value = 1;
  44. expect( spy.calledOnce ).to.be.true;
  45. } );
  46. } );
  47. describe( 'isEnabled', () => {
  48. it( 'fires change event', () => {
  49. const spy = sinon.spy();
  50. command.on( 'change:isEnabled', spy );
  51. command.isEnabled = true;
  52. expect( spy.calledOnce ).to.be.true;
  53. } );
  54. } );
  55. describe( 'execute()', () => {
  56. it( 'is decorated', () => {
  57. const spy = sinon.spy();
  58. command.on( 'execute', spy );
  59. command.execute( 1, 2 );
  60. expect( spy.calledOnce ).to.be.true;
  61. expect( spy.args[ 0 ][ 1 ] ).to.deep.equal( [ 1, 2 ] );
  62. } );
  63. } );
  64. } );