indentblockcommand.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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, doc, selection;
  10. beforeEach( () => {
  11. return ModelTestEditor
  12. .create()
  13. .then( newEditor => {
  14. editor = newEditor;
  15. model = editor.model;
  16. doc = model.document;
  17. selection = doc.selection;
  18. model.schema.register( 'paragraph', { inheritAllFrom: '$block', allowAttributes: [ 'indent' ] } );
  19. } );
  20. } );
  21. afterEach( () => {
  22. command.destroy();
  23. return editor.destroy();
  24. } );
  25. describe( 'indent', () => {
  26. describe( 'using classes', () => {
  27. beforeEach( () => {
  28. command = new IndentBlockCommand( editor, {
  29. indentBlock: {
  30. classes: [
  31. 'indent-1',
  32. 'indent-2',
  33. 'indent-3',
  34. 'indent-4'
  35. ]
  36. }
  37. } );
  38. } );
  39. describe( 'isEnabled' );
  40. describe( 'execute()' );
  41. } );
  42. describe( 'using offset', () => {
  43. beforeEach( () => {
  44. command = new IndentBlockCommand( editor, {
  45. indentBlock: {
  46. offset: 50,
  47. unit: 'px'
  48. }
  49. } );
  50. } );
  51. describe( 'isEnabled' );
  52. describe( 'execute()' );
  53. } );
  54. } );
  55. describe( 'outdent', () => {
  56. describe( 'using classes', () => {
  57. beforeEach( () => {
  58. command = new IndentBlockCommand( editor, {
  59. indentBlock: {
  60. classes: [
  61. 'indent-1',
  62. 'indent-2',
  63. 'indent-3',
  64. 'indent-4'
  65. ]
  66. }
  67. } );
  68. } );
  69. describe( 'isEnabled' );
  70. describe( 'execute()' );
  71. } );
  72. describe( 'using offset', () => {
  73. beforeEach( () => {
  74. command = new IndentBlockCommand( editor, {
  75. indentBlock: {
  76. offset: 50,
  77. unit: 'px'
  78. }
  79. } );
  80. } );
  81. describe( 'isEnabled' );
  82. describe( 'execute()' );
  83. } );
  84. } );
  85. describe( 'isEnabled', () => {
  86. it( 'should return true if characters with the attribute can be placed at caret position', () => {
  87. setData( model, '<paragraph>f[]oo</paragraph>' );
  88. expect( command.isEnabled ).to.be.true;
  89. } );
  90. } );
  91. describe( 'execute()', () => {
  92. it( 'inserts mention object if mention was passed as string', () => {
  93. setData( model, '<paragraph>foo @Jo[]bar</paragraph>' );
  94. command.execute( {
  95. marker: '@',
  96. mention: '@John',
  97. range: model.createRange( selection.focus.getShiftedBy( -3 ), selection.focus )
  98. } );
  99. // assertIndentBlock( doc.getRoot().getChild( 0 ).getChild( 1 ), '@John' );
  100. } );
  101. } );
  102. } );