indentblockcommand.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor';
  6. import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import IndentBlockCommand from '../src/indentblockcommand';
  8. describe( 'IndentBlockCommand', () => {
  9. let editor, command, model;
  10. beforeEach( () => {
  11. return ModelTestEditor
  12. .create()
  13. .then( newEditor => {
  14. editor = newEditor;
  15. model = editor.model;
  16. model.schema.register( 'paragraph', {
  17. inheritAllFrom: '$block',
  18. allowAttributes: [ 'indent' ]
  19. } );
  20. model.schema.register( 'block', { inheritAllFrom: '$block' } );
  21. } );
  22. } );
  23. afterEach( () => {
  24. command.destroy();
  25. return editor.destroy();
  26. } );
  27. describe( 'indent', () => {
  28. describe( 'using classes', () => {
  29. beforeEach( () => {
  30. command = new IndentBlockCommand( editor, {
  31. classes: [
  32. 'indent-1',
  33. 'indent-2',
  34. 'indent-3',
  35. 'indent-4'
  36. ],
  37. direction: 'forward'
  38. } );
  39. } );
  40. describe( 'isEnabled', () => {
  41. it( 'should be false in block that does not support indent', () => {
  42. setData( model, '<block>f[]oo</block>' );
  43. expect( command.isEnabled ).to.be.false;
  44. } );
  45. it( 'should be true in non-indented block', () => {
  46. setData( model, '<paragraph>f[]oo</paragraph>' );
  47. expect( command.isEnabled ).to.be.true;
  48. } );
  49. it( 'should be true in indented block and there are still indentation classes', () => {
  50. setData( model, '<paragraph indent="indent-2">f[]oo</paragraph>' );
  51. expect( command.isEnabled ).to.be.true;
  52. } );
  53. it( 'should be true in indented block in last indentation class', () => {
  54. setData( model, '<paragraph indent="indent-4">f[]oo</paragraph>' );
  55. expect( command.isEnabled ).to.be.false;
  56. } );
  57. } );
  58. describe( 'execute()', () => {} );
  59. } );
  60. describe( 'using offset', () => {
  61. beforeEach( () => {
  62. command = new IndentBlockCommand( editor, {
  63. offset: 50,
  64. unit: 'px',
  65. direction: 'forward'
  66. } );
  67. } );
  68. describe( 'isEnabled', () => {
  69. it( 'should be false in block that does not support indent', () => {
  70. setData( model, '<block>f[]oo</block>' );
  71. expect( command.isEnabled ).to.be.false;
  72. } );
  73. it( 'should be true in non-indented block', () => {
  74. setData( model, '<paragraph>f[]oo</paragraph>' );
  75. expect( command.isEnabled ).to.be.true;
  76. } );
  77. it( 'should be true in indented block', () => {
  78. setData( model, '<paragraph indent="50px">f[]oo</paragraph>' );
  79. expect( command.isEnabled ).to.be.true;
  80. } );
  81. it( 'should be true in indented block with different unit', () => {
  82. setData( model, '<paragraph indent="2em">f[]oo</paragraph>' );
  83. expect( command.isEnabled ).to.be.false;
  84. } );
  85. } );
  86. describe( 'execute()', () => {} );
  87. } );
  88. } );
  89. describe( 'outdent', () => {
  90. describe( 'using classes', () => {
  91. beforeEach( () => {
  92. command = new IndentBlockCommand( editor, {
  93. classes: [
  94. 'indent-1',
  95. 'indent-2',
  96. 'indent-3',
  97. 'indent-4'
  98. ],
  99. direction: 'backward'
  100. } );
  101. } );
  102. describe( 'isEnabled', () => {
  103. it( 'should be false in block that does not support indent', () => {
  104. setData( model, '<block>f[]oo</block>' );
  105. expect( command.isEnabled ).to.be.false;
  106. } );
  107. it( 'should be false in non-indented block', () => {
  108. setData( model, '<paragraph>f[]oo</paragraph>' );
  109. expect( command.isEnabled ).to.be.false;
  110. } );
  111. it( 'should be true in indented block and there are still indentation classes', () => {
  112. setData( model, '<paragraph indent="indent-2">f[]oo</paragraph>' );
  113. expect( command.isEnabled ).to.be.true;
  114. } );
  115. it( 'should be true in indented block in last indentation class', () => {
  116. setData( model, '<paragraph indent="indent-4">f[]oo</paragraph>' );
  117. expect( command.isEnabled ).to.be.true;
  118. } );
  119. } );
  120. describe( 'execute()', () => {} );
  121. } );
  122. describe( 'using offset', () => {
  123. beforeEach( () => {
  124. command = new IndentBlockCommand( editor, {
  125. offset: 50,
  126. unit: 'px',
  127. direction: 'backward'
  128. } );
  129. } );
  130. describe( 'isEnabled', () => {
  131. it( 'should be false in block that does not support indent', () => {
  132. setData( model, '<block>f[]oo</block>' );
  133. expect( command.isEnabled ).to.be.false;
  134. } );
  135. it( 'should be false in non-indented block', () => {
  136. setData( model, '<paragraph>f[]oo</paragraph>' );
  137. expect( command.isEnabled ).to.be.true;
  138. } );
  139. it( 'should be true in indented block', () => {
  140. setData( model, '<paragraph indent="50px">f[]oo</paragraph>' );
  141. expect( command.isEnabled ).to.be.true;
  142. } );
  143. it( 'should be true in indented block with different unit', () => {
  144. setData( model, '<paragraph indent="2em">f[]oo</paragraph>' );
  145. expect( command.isEnabled ).to.be.false;
  146. } );
  147. } );
  148. describe( 'execute()', () => {} );
  149. } );
  150. } );
  151. } );