8
0

plugin.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import Plugin from '../src/plugin';
  6. import Editor from '../src/editor/editor';
  7. describe( 'Plugin', () => {
  8. let editor;
  9. beforeEach( () => {
  10. editor = new Editor();
  11. } );
  12. it( 'should not be marked as a context plugin', () => {
  13. expect( Plugin.isContextPlugin ).to.false;
  14. } );
  15. describe( 'constructor()', () => {
  16. it( 'should set the `editor` property', () => {
  17. const plugin = new Plugin( editor );
  18. expect( plugin ).to.have.property( 'editor' ).to.equal( editor );
  19. } );
  20. } );
  21. describe( 'destroy()', () => {
  22. it( 'should be defined', () => {
  23. const plugin = new Plugin( editor );
  24. expect( plugin.destroy ).to.be.a( 'function' );
  25. } );
  26. it( 'should stop listening', () => {
  27. const plugin = new Plugin( editor );
  28. const stopListeningSpy = sinon.spy( plugin, 'stopListening' );
  29. plugin.destroy();
  30. expect( stopListeningSpy.calledOnce ).to.equal( true );
  31. } );
  32. } );
  33. describe( 'forceDisabled() / clearForceDisabled()', () => {
  34. let plugin;
  35. beforeEach( () => {
  36. plugin = new Plugin( editor );
  37. } );
  38. afterEach( () => {
  39. plugin.destroy();
  40. } );
  41. it( 'forceDisabled() should disable the plugin', () => {
  42. plugin.forceDisabled( 'foo' );
  43. plugin.isEnabled = true;
  44. expect( plugin.isEnabled ).to.be.false;
  45. } );
  46. it( 'clearForceDisabled() should enable the plugin', () => {
  47. plugin.forceDisabled( 'foo' );
  48. plugin.clearForceDisabled( 'foo' );
  49. expect( plugin.isEnabled ).to.be.true;
  50. } );
  51. it( 'clearForceDisabled() used with wrong identifier should not enable the plugin', () => {
  52. plugin.forceDisabled( 'foo' );
  53. plugin.clearForceDisabled( 'bar' );
  54. plugin.isEnabled = true;
  55. expect( plugin.isEnabled ).to.be.false;
  56. } );
  57. it( 'using forceDisabled() twice with the same identifier should not have any effect', () => {
  58. plugin.forceDisabled( 'foo' );
  59. plugin.forceDisabled( 'foo' );
  60. plugin.clearForceDisabled( 'foo' );
  61. expect( plugin.isEnabled ).to.be.true;
  62. } );
  63. it( 'plugin is enabled only after all disables were cleared', () => {
  64. plugin.forceDisabled( 'foo' );
  65. plugin.forceDisabled( 'bar' );
  66. plugin.clearForceDisabled( 'foo' );
  67. plugin.isEnabled = true;
  68. expect( plugin.isEnabled ).to.be.false;
  69. plugin.clearForceDisabled( 'bar' );
  70. expect( plugin.isEnabled ).to.be.true;
  71. } );
  72. it( 'plugin should remain disabled if isEnabled has a callback disabling it', () => {
  73. plugin.on( 'set:isEnabled', evt => {
  74. evt.return = false;
  75. evt.stop();
  76. } );
  77. plugin.forceDisabled( 'foo' );
  78. plugin.clearForceDisabled( 'foo' );
  79. plugin.isEnabled = true;
  80. expect( plugin.isEnabled ).to.be.false;
  81. } );
  82. } );
  83. } );