indentblockcommand.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. } );
  74. describe( 'execute()', () => {} );
  75. } );
  76. } );
  77. describe( 'outdent', () => {
  78. describe( 'using classes', () => {
  79. beforeEach( () => {
  80. command = new IndentBlockCommand( editor, {
  81. classes: [
  82. 'indent-1',
  83. 'indent-2',
  84. 'indent-3',
  85. 'indent-4'
  86. ],
  87. direction: 'backward'
  88. } );
  89. } );
  90. describe( 'isEnabled', () => {
  91. it( 'should be false in block that does not support indent', () => {
  92. setData( model, '<block>f[]oo</block>' );
  93. expect( command.isEnabled ).to.be.false;
  94. } );
  95. it( 'should be false in non-indented block', () => {
  96. setData( model, '<paragraph>f[]oo</paragraph>' );
  97. expect( command.isEnabled ).to.be.false;
  98. } );
  99. it( 'should be true in indented block and there are still indentation classes', () => {
  100. setData( model, '<paragraph indent="indent-2">f[]oo</paragraph>' );
  101. expect( command.isEnabled ).to.be.true;
  102. } );
  103. it( 'should be true in indented block in last indentation class', () => {
  104. setData( model, '<paragraph indent="indent-4">f[]oo</paragraph>' );
  105. expect( command.isEnabled ).to.be.true;
  106. } );
  107. } );
  108. describe( 'execute()', () => {} );
  109. } );
  110. describe( 'using offset', () => {
  111. beforeEach( () => {
  112. command = new IndentBlockCommand( editor, {
  113. offset: 50,
  114. unit: 'px',
  115. direction: 'backward'
  116. } );
  117. } );
  118. describe( 'isEnabled', () => {
  119. it( 'should be false in block that does not support indent', () => {
  120. setData( model, '<block>f[]oo</block>' );
  121. expect( command.isEnabled ).to.be.false;
  122. } );
  123. } );
  124. describe( 'execute()', () => {} );
  125. } );
  126. } );
  127. } );