indentblock-integration.js 2.7 KB

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