standardeditingmodeui.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /* 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 StandardEditingModeUI from '../src/standardeditingmodeui';
  11. import StandardEditingModeEditing from '../src/standardeditingmodeediting';
  12. describe( 'StandardEditingModeUI', () => {
  13. let editor, buttonView, editorElement;
  14. testUtils.createSinonSandbox();
  15. beforeEach( async () => {
  16. editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. editor = await ClassicTestEditor.create( editorElement, {
  19. plugins: [ Paragraph, StandardEditingModeEditing, StandardEditingModeUI ]
  20. } );
  21. buttonView = editor.ui.componentFactory.create( 'restrictedEditingException' );
  22. } );
  23. afterEach( () => {
  24. editorElement.remove();
  25. return editor.destroy();
  26. } );
  27. it( 'should register a button', () => {
  28. expect( buttonView ).to.be.instanceOf( ButtonView );
  29. expect( buttonView.isOn ).to.be.false;
  30. expect( buttonView.label ).to.equal( 'Enable editing' );
  31. expect( buttonView.icon ).to.match( /<svg / );
  32. expect( buttonView.isToggleable ).to.be.true;
  33. } );
  34. it( 'should execute a command on the button "execute" event', () => {
  35. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  36. buttonView.fire( 'execute' );
  37. sinon.assert.calledOnce( executeSpy );
  38. } );
  39. it( 'should bind a button to the command', () => {
  40. const command = editor.commands.get( 'restrictedEditingException' );
  41. expect( buttonView.isOn ).to.be.false;
  42. expect( buttonView.isEnabled ).to.be.true;
  43. command.value = true;
  44. expect( buttonView.isOn ).to.be.true;
  45. command.isEnabled = false;
  46. expect( buttonView.isEnabled ).to.be.false;
  47. } );
  48. } );