indentui.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. /* 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. import indentIcon from '../theme/icons/indent.svg';
  12. import outdentIcon from '../theme/icons/outdent.svg';
  13. describe( 'IndentUI', () => {
  14. let editor, element;
  15. testUtils.createSinonSandbox();
  16. beforeEach( () => {
  17. element = document.createElement( 'div' );
  18. document.body.appendChild( element );
  19. return ClassicTestEditor
  20. .create( element, { plugins: [ IndentUI, IndentEditing ] } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. } );
  24. } );
  25. afterEach( () => {
  26. element.remove();
  27. if ( editor ) {
  28. return editor.destroy();
  29. }
  30. } );
  31. it( 'should be named', () => {
  32. expect( IndentUI.pluginName ).to.equal( 'IndentUI' );
  33. } );
  34. it( 'should be loaded', () => {
  35. expect( editor.plugins.get( IndentUI ) ).to.be.instanceOf( IndentUI );
  36. } );
  37. it( 'should set up button for indent', () => {
  38. const indentButton = editor.ui.componentFactory.create( 'indent' );
  39. expect( indentButton ).to.be.instanceOf( ButtonView );
  40. expect( indentButton.label ).to.equal( 'Increase indent' );
  41. } );
  42. it( 'should set up button for outdent', () => {
  43. const outdentButton = editor.ui.componentFactory.create( 'outdent' );
  44. expect( outdentButton ).to.be.instanceOf( ButtonView );
  45. expect( outdentButton.label ).to.equal( 'Decrease indent' );
  46. } );
  47. describe( 'icons', () => {
  48. describe( 'left–to–right UI', () => {
  49. it( 'should display the right icon for indent', () => {
  50. const indentButton = editor.ui.componentFactory.create( 'indent' );
  51. expect( indentButton.icon ).to.equal( indentIcon );
  52. } );
  53. it( 'should display the right icon for outdent', () => {
  54. const outdentButton = editor.ui.componentFactory.create( 'outdent' );
  55. expect( outdentButton.icon ).to.equal( outdentIcon );
  56. } );
  57. } );
  58. describe( 'right–to–left UI', () => {
  59. it( 'should display the right icon for indent', () => {
  60. const element = document.createElement( 'div' );
  61. document.body.appendChild( element );
  62. return ClassicTestEditor
  63. .create( element, {
  64. plugins: [ IndentUI, IndentEditing ],
  65. language: 'ar'
  66. } )
  67. .then( newEditor => {
  68. const indentButton = newEditor.ui.componentFactory.create( 'indent' );
  69. expect( indentButton.icon ).to.equal( outdentIcon );
  70. return newEditor.destroy();
  71. } )
  72. .then( () => {
  73. element.remove();
  74. } );
  75. } );
  76. it( 'should display the right icon for outdent', () => {
  77. const element = document.createElement( 'div' );
  78. document.body.appendChild( element );
  79. return ClassicTestEditor
  80. .create( element, {
  81. plugins: [ IndentUI, IndentEditing ],
  82. language: 'ar'
  83. } )
  84. .then( newEditor => {
  85. const outdentButton = newEditor.ui.componentFactory.create( 'outdent' );
  86. expect( outdentButton.icon ).to.equal( indentIcon );
  87. return newEditor.destroy();
  88. } )
  89. .then( () => {
  90. element.remove();
  91. } );
  92. } );
  93. } );
  94. } );
  95. it( 'should execute indent command on button execute', () => {
  96. const button = editor.ui.componentFactory.create( 'indent' );
  97. const spy = sinon.spy( editor, 'execute' );
  98. button.fire( 'execute' );
  99. sinon.assert.calledOnce( spy );
  100. sinon.assert.calledWithExactly( spy, 'indent' );
  101. } );
  102. it( 'should execute outdent command on button execute', () => {
  103. const button = editor.ui.componentFactory.create( 'outdent' );
  104. const spy = sinon.spy( editor, 'execute' );
  105. button.fire( 'execute' );
  106. sinon.assert.calledOnce( spy );
  107. sinon.assert.calledWithExactly( spy, 'outdent' );
  108. } );
  109. } );