8
0

integration.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 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 format from attribute wrapped around another attribute', () => {
  64. // Edge case reported in https://github.com/ckeditor/ckeditor5-remove-format/pull/1#pullrequestreview-220515609
  65. setModelData( model, '<paragraph>' +
  66. 'f[<$text underline="true">o</$text>' +
  67. '<$text underline="true" bold="true">ob</$text>' +
  68. '<$text underline="true">a</$text>]r' +
  69. '</paragraph>' );
  70. editor.execute( 'removeFormat' );
  71. expect( getModelData( model ) ).to.equal( '<paragraph>f[ooba]r</paragraph>' );
  72. } );
  73. } );
  74. } );