8
0

integration.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import RemoveFormat from '../src/removeformat';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import Heading from '@ckeditor/ckeditor5-heading/src/heading';
  9. import Image from '@ckeditor/ckeditor5-image/src/image';
  10. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  11. import Link from '@ckeditor/ckeditor5-link/src/link';
  12. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  13. import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
  14. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  15. import {
  16. getData as getModelData,
  17. setData as setModelData
  18. } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  19. describe( 'RemoveFormat', () => {
  20. let editor, model, element;
  21. beforeEach( () => {
  22. element = document.createElement( 'div' );
  23. document.body.appendChild( element );
  24. return ClassicTestEditor
  25. .create( element, {
  26. plugins: [ Paragraph, Heading, Image, Bold, Underline, RemoveFormat, Image, ImageCaption, Link ]
  27. } )
  28. .then( newEditor => {
  29. editor = newEditor;
  30. model = editor.model;
  31. } );
  32. } );
  33. afterEach( () => {
  34. element.remove();
  35. return editor.destroy();
  36. } );
  37. describe( 'works correctly with multiline ranges', () => {
  38. it( 'does remove pure formatting markup', () => {
  39. setModelData( model, '<paragraph>foo[<$text bold="true">foo</$text></paragraph>' +
  40. '<paragraph><$text bold="true">bar</$text>]bar</paragraph>' );
  41. editor.execute( 'removeFormat' );
  42. expect( getModelData( model ) )
  43. .to.equal( '<paragraph>foo[foo</paragraph><paragraph>bar]bar</paragraph>' );
  44. } );
  45. it( 'does not touch non-formatting markup', () => {
  46. setModelData( model, '<paragraph>[<$text linkHref="url">foo</$text></paragraph><image src="assets/sample.png">' +
  47. '<caption>caption</caption></image><paragraph>bar]</paragraph>' );
  48. editor.execute( 'removeFormat' );
  49. expect( getModelData( model ) )
  50. .to.equal( '<paragraph>[<$text linkHref="url">foo</$text></paragraph>' +
  51. '<image src="assets/sample.png"><caption>caption</caption></image><paragraph>bar]</paragraph>' );
  52. } );
  53. it( 'removes the content from within widget editable', () => {
  54. setModelData( model, '<paragraph>[</paragraph>' +
  55. '<image src="assets/sample.png"><caption><$text bold="true">foo</$text></caption></image><paragraph>bar]</paragraph>' );
  56. editor.execute( 'removeFormat' );
  57. expect( getModelData( model ) )
  58. .to.equal( '<paragraph>' +
  59. '[</paragraph><image src="assets/sample.png"><caption>foo</caption></image><paragraph>bar]</paragraph>' );
  60. } );
  61. } );
  62. describe( 'Handles correctly known issues', () => {
  63. it( 'doesn\'t break after removing subsequently applied style', () => {
  64. // https://github.com/ckeditor/ckeditor5-remove-format/pull/1#pullrequestreview-220515609
  65. setModelData( model, '<paragraph>f[o<$text bold="true">ob</$text>a]r</paragraph>' );
  66. editor.execute( 'underline' );
  67. editor.execute( 'removeFormat' );
  68. expect( getModelData( model ) ).to.equal( '<paragraph>foobar</paragraph>' );
  69. } );
  70. } );
  71. } );