8
0

indentblock-integration.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
  10. import IndentEditing from '../src/indentediting';
  11. import IndentBlock from '../src/indentblock';
  12. describe( 'IndentBlock - integration', () => {
  13. let editor, doc;
  14. testUtils.createSinonSandbox();
  15. afterEach( () => {
  16. if ( editor ) {
  17. return editor.destroy();
  18. }
  19. } );
  20. describe( 'with paragraph', () => {
  21. beforeEach( () => {
  22. return createTestEditor( { indentBlock: { offset: 50, unit: 'px' } } )
  23. .then( newEditor => {
  24. editor = newEditor;
  25. doc = editor.model.document;
  26. } );
  27. } );
  28. it( 'should work with paragraph set', () => {
  29. editor.setData( '<p style="margin-left:50px">foo</p>' );
  30. const paragraph = doc.getRoot().getChild( 0 );
  31. expect( paragraph.hasAttribute( 'blockIndent' ) ).to.be.true;
  32. expect( paragraph.getAttribute( 'blockIndent' ) ).to.equal( '50px' );
  33. expect( editor.getData() ).to.equal( '<p style="margin-left:50px;">foo</p>' );
  34. expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
  35. .to.equal( '<p style="margin-left:50px">foo</p>' );
  36. } );
  37. } );
  38. describe( 'with heading', () => {
  39. beforeEach( () => {
  40. return createTestEditor( {
  41. plugins: [ Paragraph, HeadingEditing, IndentEditing, IndentBlock ],
  42. indentBlock: { offset: 50, unit: 'px' }
  43. } ).then( newEditor => {
  44. editor = newEditor;
  45. doc = editor.model.document;
  46. } );
  47. } );
  48. it( 'should work with default headings set', () => {
  49. editor.setData( '<p style="margin-left:50px">foo</p>' );
  50. const paragraph = doc.getRoot().getChild( 0 );
  51. expect( paragraph.hasAttribute( 'blockIndent' ) ).to.be.true;
  52. expect( paragraph.getAttribute( 'blockIndent' ) ).to.equal( '50px' );
  53. expect( editor.getData() ).to.equal( '<p style="margin-left:50px;">foo</p>' );
  54. expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
  55. .to.equal( '<p style="margin-left:50px">foo</p>' );
  56. } );
  57. } );
  58. // https://github.com/ckeditor/ckeditor5/issues/2359
  59. it( 'should work with paragraphs regardless of plugin order', () => {
  60. return createTestEditor( {
  61. plugins: [ IndentEditing, IndentBlock, Paragraph, HeadingEditing ],
  62. indentBlock: { offset: 50, unit: 'px' }
  63. } ).then( newEditor => {
  64. editor = newEditor;
  65. doc = editor.model.document;
  66. editor.setData( '<p style="margin-left:50px">foo</p>' );
  67. const paragraph = doc.getRoot().getChild( 0 );
  68. expect( paragraph.hasAttribute( 'blockIndent' ) ).to.be.true;
  69. } );
  70. } );
  71. function createTestEditor( extraConfig = {} ) {
  72. return VirtualTestEditor
  73. .create( Object.assign( {
  74. plugins: [ Paragraph, IndentEditing, IndentBlock ]
  75. }, extraConfig ) );
  76. }
  77. } );