linkimage-integration.js 2.2 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. import Image from '@ckeditor/ckeditor5-image/src/image';
  6. import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption';
  7. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  8. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  11. import Link from '../src/link';
  12. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  13. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  14. describe( 'LinkImage integration', () => {
  15. let editorElement, editor, model;
  16. beforeEach( () => {
  17. editorElement = global.document.createElement( 'div' );
  18. global.document.body.appendChild( editorElement );
  19. } );
  20. afterEach( () => {
  21. editorElement.remove();
  22. } );
  23. describe( 'when LinkImage is not loaded', () => {
  24. beforeEach( () => {
  25. return ClassicEditor
  26. .create( editorElement, {
  27. plugins: [
  28. Enter, Typing, Paragraph, Image, ImageCaption, Link
  29. ]
  30. } )
  31. .then( newEditor => {
  32. editor = newEditor;
  33. model = editor.model;
  34. } );
  35. } );
  36. afterEach( () => {
  37. return editor.destroy();
  38. } );
  39. it( 'link command should link a figcaption element if an image is selected', () => {
  40. setModelData(
  41. model,
  42. '<paragraph>Foo.</paragraph>[<image src="/assets/sample.png"><caption>Foo.</caption></image>]'
  43. );
  44. editor.execute( 'link', 'https://cksource.com' );
  45. expect( getModelData( model ) ).to.equal(
  46. '<paragraph>Foo.</paragraph>' +
  47. '[<image src="/assets/sample.png"><caption><$text linkHref="https://cksource.com">Foo.</$text></caption></image>]'
  48. );
  49. } );
  50. it( 'unlink command should be enabled when an image with a linked figcaption is selected', () => {
  51. setModelData(
  52. model,
  53. '<paragraph>Foo.</paragraph>' +
  54. '[<image src="/assets/sample.png"><caption><$text linkHref="https://cksource.com">Foo.</$text></caption></image>]'
  55. );
  56. expect( editor.commands.get( 'unlink' ).isEnabled ).to.equal( true );
  57. } );
  58. } );
  59. } );