integration.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 Highlight from '../src/highlight';
  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( 'Highlight', () => {
  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: [ Highlight, 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 work inside image caption', () => {
  37. setModelData( model, '<image src="/assets/sample.png"><caption>foo[bar]baz</caption></image>' );
  38. editor.execute( 'highlight', { value: 'yellowMarker' } );
  39. expect( getModelData( model ) )
  40. .to.equal(
  41. '<image src="/assets/sample.png"><caption>foo[<$text highlight="yellowMarker">bar</$text>]baz</caption></image>'
  42. );
  43. } );
  44. it( 'does work on selection with image', () => {
  45. setModelData(
  46. model,
  47. '<paragraph>foo[foo</paragraph><image src="/assets/sample.png"><caption>abc</caption></image><paragraph>bar]bar</paragraph>'
  48. );
  49. editor.execute( 'highlight', { value: 'yellowMarker' } );
  50. expect( getModelData( model ) ).to.equal(
  51. '<paragraph>foo[<$text highlight="yellowMarker">foo</$text></paragraph>' +
  52. '<image src="/assets/sample.png"><caption><$text highlight="yellowMarker">abc</$text></caption></image>' +
  53. '<paragraph><$text highlight="yellowMarker">bar</$text>]bar</paragraph>'
  54. );
  55. } );
  56. } );
  57. } );