indentui.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 '../_utils/classictesteditor';
  7. import testUtils from '../_utils/utils';
  8. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  9. import IndentEditing from '../../src/indent/indentediting';
  10. import IndentUI from '../../src/indent/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. } );
  39. it( 'should set up button for indent', () => {
  40. const outdentButton = editor.ui.componentFactory.create( 'outdent' );
  41. expect( outdentButton ).to.be.instanceOf( ButtonView );
  42. } );
  43. it( 'should execute indent command on button execute', () => {
  44. const button = editor.ui.componentFactory.create( 'indent' );
  45. const spy = sinon.spy( editor, 'execute' );
  46. button.fire( 'execute' );
  47. sinon.assert.calledOnce( spy );
  48. sinon.assert.calledWithExactly( spy, 'indent' );
  49. } );
  50. it( 'should execute outdent command on button execute', () => {
  51. const button = editor.ui.componentFactory.create( 'outdent' );
  52. const spy = sinon.spy( editor, 'execute' );
  53. button.fire( 'execute' );
  54. sinon.assert.calledOnce( spy );
  55. sinon.assert.calledWithExactly( spy, 'outdent' );
  56. } );
  57. } );