integration.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /* global document */
  6. import Alignment from '../src/alignment';
  7. import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import Heading from '@ckeditor/ckeditor5-heading/src/heading';
  10. import Image from '@ckeditor/ckeditor5-image/src/image';
  11. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  12. import List from '@ckeditor/ckeditor5-list/src/list';
  13. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  14. import Delete from '@ckeditor/ckeditor5-typing/src/delete';
  15. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  16. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  17. describe( 'Alignment integration', () => {
  18. let editor, model, element;
  19. beforeEach( () => {
  20. element = document.createElement( 'div' );
  21. document.body.appendChild( element );
  22. return ClassicTestEditor
  23. .create( element, {
  24. plugins: [ Alignment, BlockQuote, Paragraph, Heading, Image, ImageCaption, List, Enter, Delete ]
  25. } )
  26. .then( newEditor => {
  27. editor = newEditor;
  28. model = editor.model;
  29. } );
  30. } );
  31. afterEach( () => {
  32. element.remove();
  33. return editor.destroy();
  34. } );
  35. describe( 'compatibility with images', () => {
  36. it( 'does not work inside image caption', () => {
  37. setModelData( model, '<image src="/assets/sample.png"><caption>Foo[]</caption></image>' );
  38. editor.execute( 'alignment', { value: 'center' } );
  39. expect( getModelData( model ) ).to.equal( '<image src="/assets/sample.png"><caption>Foo[]</caption></image>' );
  40. } );
  41. it( 'does not work inside image caption when selection overlaps image', () => {
  42. setModelData(
  43. model,
  44. '<paragraph>foo[foo</paragraph>' +
  45. '<image src="/assets/sample.png"><caption>bar</caption></image>' +
  46. '<paragraph>baz]baz</paragraph>'
  47. );
  48. editor.execute( 'alignment', { value: 'center' } );
  49. expect( getModelData( model ) ).to.equal(
  50. '<paragraph alignment="center">foo[foo</paragraph>' +
  51. '<image src="/assets/sample.png"><caption>bar</caption></image>' +
  52. '<paragraph alignment="center">baz]baz</paragraph>'
  53. );
  54. } );
  55. } );
  56. describe( 'compatibility with blockQuote', () => {
  57. it( 'does work inside BlockQuote on paragraph', () => {
  58. setModelData( model, '<blockQuote><paragraph>Foo[]</paragraph></blockQuote>' );
  59. editor.execute( 'alignment', { value: 'center' } );
  60. expect( getModelData( model ) ).to.equal( '<blockQuote><paragraph alignment="center">Foo[]</paragraph></blockQuote>' );
  61. } );
  62. it( 'does work inside blockQuote on heading', () => {
  63. setModelData( model, '<blockQuote><heading1>Foo[]</heading1></blockQuote>' );
  64. editor.execute( 'alignment', { value: 'center' } );
  65. expect( getModelData( model ) ).to.equal( '<blockQuote><heading1 alignment="center">Foo[]</heading1></blockQuote>' );
  66. } );
  67. it( 'does work inside blockQuote on listItem', () => {
  68. setModelData( model, '<blockQuote><listItem listIndent="0" listType="numbered">Foo[]</listItem></blockQuote>' );
  69. editor.execute( 'alignment', { value: 'center' } );
  70. expect( getModelData( model ) ).to.equal(
  71. '<blockQuote><listItem alignment="center" listIndent="0" listType="numbered">Foo[]</listItem></blockQuote>'
  72. );
  73. } );
  74. } );
  75. } );