8
0

pagebreakui.js 2.0 KB

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