restricteddocumentui.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  8. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import RestrictedDocumentUI from '../src/restricteddocumentui';
  11. import RestrictedDocument from '../src/restricteddocument';
  12. describe( 'RestrictedDocumentUI', () => {
  13. let editor, buttonView;
  14. testUtils.createSinonSandbox();
  15. beforeEach( () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor
  19. .create( editorElement, {
  20. plugins: [ Paragraph, RestrictedDocument, RestrictedDocumentUI ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. buttonView = editor.ui.componentFactory.create( 'nonRestricted' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. return editor.destroy();
  29. } );
  30. it( 'should register button', () => {
  31. expect( buttonView ).to.be.instanceOf( ButtonView );
  32. expect( buttonView.isOn ).to.be.false;
  33. expect( buttonView.label ).to.equal( 'Restricted editing' );
  34. expect( buttonView.icon ).to.match( /<svg / );
  35. expect( buttonView.isToggleable ).to.be.true;
  36. } );
  37. it( 'should execute command on model execute event', () => {
  38. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  39. buttonView.fire( 'execute' );
  40. sinon.assert.calledOnce( executeSpy );
  41. } );
  42. it( 'should bind model to command', () => {
  43. const command = editor.commands.get( 'nonRestricted' );
  44. expect( buttonView.isOn ).to.be.false;
  45. expect( buttonView.isEnabled ).to.be.true;
  46. command.value = true;
  47. expect( buttonView.isOn ).to.be.true;
  48. command.isEnabled = false;
  49. expect( buttonView.isEnabled ).to.be.false;
  50. } );
  51. } );