restrictededitingexceptionui.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals document */
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  8. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import RestrictedEditingExceptionUI from '../src/restrictededitingexceptionui';
  11. import RestrictedEditingException from '../src/restrictededitingexception';
  12. describe( 'RestrictedEditingExceptionUI', () => {
  13. let editor, buttonView;
  14. testUtils.createSinonSandbox();
  15. beforeEach( async () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. editor = await ClassicTestEditor.create( editorElement, {
  19. plugins: [ Paragraph, RestrictedEditingException, RestrictedEditingExceptionUI ]
  20. } );
  21. buttonView = editor.ui.componentFactory.create( 'restrictedEditingException' );
  22. } );
  23. afterEach( () => {
  24. return editor.destroy();
  25. } );
  26. it( 'should register a button', () => {
  27. expect( buttonView ).to.be.instanceOf( ButtonView );
  28. expect( buttonView.isOn ).to.be.false;
  29. expect( buttonView.label ).to.equal( 'Enable editing' );
  30. expect( buttonView.icon ).to.match( /<svg / );
  31. expect( buttonView.isToggleable ).to.be.true;
  32. } );
  33. it( 'should execute a command on the button "execute" event', () => {
  34. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  35. buttonView.fire( 'execute' );
  36. sinon.assert.calledOnce( executeSpy );
  37. } );
  38. it( 'should bind a button to the command', () => {
  39. const command = editor.commands.get( 'restrictedEditingException' );
  40. expect( buttonView.isOn ).to.be.false;
  41. expect( buttonView.isEnabled ).to.be.true;
  42. command.value = true;
  43. expect( buttonView.isOn ).to.be.true;
  44. command.isEnabled = false;
  45. expect( buttonView.isEnabled ).to.be.false;
  46. } );
  47. } );