link.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import Heading from '@ckeditor/ckeditor5-heading/src/heading';
  10. import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
  11. import Link from '@ckeditor/ckeditor5-link/src/link';
  12. import ShiftEnter from '@ckeditor/ckeditor5-enter/src/shiftenter';
  13. import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  14. import { getFixtures } from '../../_utils/fixtures';
  15. import { expectModel } from '../../_utils/utils';
  16. describe( 'Link – integration', () => {
  17. let element, editor, input;
  18. before( () => {
  19. input = getFixtures( 'link' ).input;
  20. element = document.createElement( 'div' );
  21. document.body.appendChild( element );
  22. return ClassicTestEditor
  23. .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Link, ShiftEnter ] } )
  24. .then( editorInstance => {
  25. editor = editorInstance;
  26. } );
  27. } );
  28. beforeEach( () => {
  29. setData( editor.model, '<paragraph>[]</paragraph>' );
  30. } );
  31. after( () => {
  32. editor.destroy();
  33. element.remove();
  34. } );
  35. // Pastes:
  36. // 'Regular <a href="https://ckeditor.com/">link</a>1'
  37. it( 'pastes link within text', () => {
  38. const expected = '<paragraph>Regular <$text linkHref="https://ckeditor.com/">link</$text>1</paragraph>';
  39. expectModel( editor, input.withinText, expected );
  40. } );
  41. // Pastes:
  42. // '<a href="https://ckeditor.com/">CKEditor</a><a href="https://cksource.com/">CKSource</a> 2'
  43. it( 'pastes combined links', () => {
  44. const expected = '<paragraph><$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
  45. '<$text linkHref="https://cksource.com/">CKSource</$text> 2</paragraph>';
  46. expectModel( editor, input.combined, expected );
  47. } );
  48. // Pastes:
  49. // '<a href="https://cksource.com/">Long link <br> WITH spaces</a>'
  50. it( 'pastes two line link', () => {
  51. const expected = '<paragraph><$text linkHref="https://cksource.com/">Long link </$text><softBreak></softBreak>' +
  52. '<$text linkHref="https://cksource.com/">WITH spaces</$text></paragraph>';
  53. expectModel( editor, input.twoLine, expected );
  54. } );
  55. } );