indentblock-integration.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 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 IndentEditing from '@ckeditor/ckeditor5-core/src/indent/indentediting';
  10. import HeadingEditing from '@ckeditor/ckeditor5-heading/src/headingediting';
  11. import IndentBlock from '../src/indentblock';
  12. describe( 'IndentBlock - integration', () => {
  13. let editor, model, 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. model = editor.model;
  26. doc = model.document;
  27. } );
  28. } );
  29. it( 'should work with paragraph set', () => {
  30. editor.setData( '<p style="margin-left:50px">foo</p>' );
  31. const paragraph = doc.getRoot().getChild( 0 );
  32. expect( paragraph.hasAttribute( 'blockIndent' ) ).to.be.true;
  33. expect( paragraph.getAttribute( 'blockIndent' ) ).to.equal( '50px' );
  34. expect( editor.getData() ).to.equal( '<p style="margin-left:50px;">foo</p>' );
  35. expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
  36. .to.equal( '<p style="margin-left:50px">foo</p>' );
  37. } );
  38. } );
  39. describe( 'with heading', () => {
  40. beforeEach( () => {
  41. return createTestEditor( {
  42. plugins: [ Paragraph, HeadingEditing, IndentEditing, IndentBlock ],
  43. indentBlock: { offset: 50, unit: 'px' }
  44. } ).then( newEditor => {
  45. editor = newEditor;
  46. model = editor.model;
  47. doc = model.document;
  48. } );
  49. } );
  50. it( 'should work with default headings set', () => {
  51. editor.setData( '<p style="margin-left:50px">foo</p>' );
  52. const paragraph = doc.getRoot().getChild( 0 );
  53. expect( paragraph.hasAttribute( 'blockIndent' ) ).to.be.true;
  54. expect( paragraph.getAttribute( 'blockIndent' ) ).to.equal( '50px' );
  55. expect( editor.getData() ).to.equal( '<p style="margin-left:50px;">foo</p>' );
  56. expect( getViewData( editor.editing.view, { withoutSelection: true } ) )
  57. .to.equal( '<p style="margin-left:50px">foo</p>' );
  58. } );
  59. } );
  60. function createTestEditor( extraConfig = {} ) {
  61. return VirtualTestEditor
  62. .create( Object.assign( {
  63. plugins: [ Paragraph, IndentEditing, IndentBlock ]
  64. }, extraConfig ) );
  65. }
  66. } );