indentui.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /* global document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  8. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  9. import IndentEditing from '../src/indentediting';
  10. import IndentUI from '../src/indentui';
  11. describe( 'IndentUI', () => {
  12. let editor, element;
  13. testUtils.createSinonSandbox();
  14. beforeEach( () => {
  15. element = document.createElement( 'div' );
  16. document.body.appendChild( element );
  17. return ClassicTestEditor
  18. .create( element, { plugins: [ IndentUI, IndentEditing ] } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. } );
  22. } );
  23. afterEach( () => {
  24. element.remove();
  25. if ( editor ) {
  26. return editor.destroy();
  27. }
  28. } );
  29. it( 'should be named', () => {
  30. expect( IndentUI.pluginName ).to.equal( 'IndentUI' );
  31. } );
  32. it( 'should be loaded', () => {
  33. expect( editor.plugins.get( IndentUI ) ).to.be.instanceOf( IndentUI );
  34. } );
  35. it( 'should set up button for indent', () => {
  36. const indentButton = editor.ui.componentFactory.create( 'indent' );
  37. expect( indentButton ).to.be.instanceOf( ButtonView );
  38. expect( indentButton.label ).to.equal( 'Increase indent' );
  39. expect( indentButton.icon ).to.match( /<svg / );
  40. } );
  41. it( 'should set up button for outdent', () => {
  42. const outdentButton = editor.ui.componentFactory.create( 'outdent' );
  43. expect( outdentButton ).to.be.instanceOf( ButtonView );
  44. expect( outdentButton.label ).to.equal( 'Decrease indent' );
  45. expect( outdentButton.icon ).to.match( /<svg / );
  46. } );
  47. it( 'should execute indent command on button execute', () => {
  48. const button = editor.ui.componentFactory.create( 'indent' );
  49. const spy = sinon.spy( editor, 'execute' );
  50. button.fire( 'execute' );
  51. sinon.assert.calledOnce( spy );
  52. sinon.assert.calledWithExactly( spy, 'indent' );
  53. } );
  54. it( 'should execute outdent command on button execute', () => {
  55. const button = editor.ui.componentFactory.create( 'outdent' );
  56. const spy = sinon.spy( editor, 'execute' );
  57. button.fire( 'execute' );
  58. sinon.assert.calledOnce( spy );
  59. sinon.assert.calledWithExactly( spy, 'outdent' );
  60. } );
  61. } );