8
0

link.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 { expectPaste } from '../../_utils/utils';
  15. import withinText from '../../_data/link/within-text/input.word2016.html';
  16. import combined from '../../_data/link/combined/input.word2016.html';
  17. import twoLine from '../../_data/link/two-line/input.word2016.html';
  18. describe( 'Link – integration', () => {
  19. let element, editor;
  20. before( () => {
  21. element = document.createElement( 'div' );
  22. document.body.appendChild( element );
  23. return ClassicTestEditor
  24. .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Link, ShiftEnter ] } )
  25. .then( editorInstance => {
  26. editor = editorInstance;
  27. } );
  28. } );
  29. beforeEach( () => {
  30. setData( editor.model, '<paragraph>[]</paragraph>' );
  31. } );
  32. after( () => {
  33. editor.destroy();
  34. element.remove();
  35. } );
  36. // Pastes: 'Regular <a href="https://ckeditor.com/">link</a>1'
  37. // Input same for: Chrome, Firefox and Edge.
  38. describe( 'within text', () => {
  39. it( 'pastes in the empty editor', () => {
  40. expectPaste( editor, withinText, '<paragraph>Regular ' +
  41. '<$text linkHref="https://ckeditor.com/">link</$text>1[]</paragraph>' );
  42. } );
  43. it( 'pastes in the paragraph', () => {
  44. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  45. expectPaste( editor, withinText, '<paragraph>More Regular ' +
  46. '<$text linkHref="https://ckeditor.com/">link</$text>1[] text</paragraph>' );
  47. } );
  48. it( 'pastes in the different block context', () => {
  49. setData( editor.model, '<heading1>More [] text</heading1>' );
  50. expectPaste( editor, withinText, '<heading1>More Regular ' +
  51. '<$text linkHref="https://ckeditor.com/">link</$text>1[] text</heading1>' );
  52. } );
  53. it( 'pastes in the inline styling context', () => {
  54. setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
  55. expectPaste( editor, withinText, '<paragraph><$text bold="true">Bo</$text>' +
  56. 'Regular <$text linkHref="https://ckeditor.com/">link</$text>1[]<$text bold="true">ld</$text></paragraph>' );
  57. } );
  58. it( 'pastes inside another link element', () => {
  59. setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
  60. expectPaste( editor, withinText, '<paragraph>1<$text linkHref="#test">tes</$text>' +
  61. 'Regular <$text linkHref="https://ckeditor.com/">link</$text>1[]<$text linkHref="#test">t</$text>2</paragraph>' );
  62. } );
  63. } );
  64. // Pastes: '<a href="https://ckeditor.com/">CKEditor</a><a href="https://cksource.com/">CKSource</a> 2'
  65. // Input same for: Chrome, Firefox and Edge.
  66. describe( 'combined', () => {
  67. it( 'pastes in the empty editor', () => {
  68. expectPaste( editor, combined, '<paragraph><$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
  69. '<$text linkHref="https://cksource.com/">CKSource</$text> 2[]</paragraph>' );
  70. } );
  71. it( 'pastes in the paragraph', () => {
  72. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  73. expectPaste( editor, combined, '<paragraph>More <$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
  74. '<$text linkHref="https://cksource.com/">CKSource</$text> 2[] text</paragraph>' );
  75. } );
  76. it( 'pastes in the different block context', () => {
  77. setData( editor.model, '<heading1>More [] text</heading1>' );
  78. expectPaste( editor, combined, '<heading1>More <$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
  79. '<$text linkHref="https://cksource.com/">CKSource</$text> 2[] text</heading1>' );
  80. } );
  81. it( 'pastes in the inline styling context', () => {
  82. setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
  83. expectPaste( editor, combined, '<paragraph><$text bold="true">Bo</$text>' +
  84. '<$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
  85. '<$text linkHref="https://cksource.com/">CKSource</$text> 2[]' +
  86. '<$text bold="true">ld</$text></paragraph>' );
  87. } );
  88. it( 'pastes inside another link element', () => {
  89. setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
  90. expectPaste( editor, combined, '<paragraph>1<$text linkHref="#test">tes</$text>' +
  91. '<$text linkHref="https://ckeditor.com/">CKEditor</$text>' +
  92. '<$text linkHref="https://cksource.com/">CKSource</$text> 2[]' +
  93. '<$text linkHref="#test">t</$text>2</paragraph>' );
  94. } );
  95. } );
  96. // Pastes: '<a href="https://cksource.com/">Long link <br> WITH spaces</a>'
  97. // Input same for: Chrome, Firefox and Edge.
  98. describe( 'two line', () => {
  99. it( 'pastes in the empty editor', () => {
  100. expectPaste( editor, twoLine, '<paragraph><$text linkHref="https://cksource.com/">Long link </$text><softBreak></softBreak>' +
  101. '<$text linkHref="https://cksource.com/">WITH spaces[]</$text></paragraph>' );
  102. } );
  103. it( 'pastes in the paragraph', () => {
  104. setData( editor.model, '<paragraph>More [] text</paragraph>' );
  105. expectPaste( editor, twoLine, '<paragraph>More <$text linkHref="https://cksource.com/">Long link </$text>' +
  106. '<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text> text</paragraph>' );
  107. } );
  108. it( 'pastes in the different block context', () => {
  109. setData( editor.model, '<heading1>More [] text</heading1>' );
  110. expectPaste( editor, twoLine, '<heading1>More <$text linkHref="https://cksource.com/">Long link </$text>' +
  111. '<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text> text</heading1>' );
  112. } );
  113. it( 'pastes in the inline styling context', () => {
  114. setData( editor.model, '<paragraph><$text bold="true">Bo[]ld</$text></paragraph>' );
  115. expectPaste( editor, twoLine, '<paragraph><$text bold="true">Bo</$text>' +
  116. '<$text linkHref="https://cksource.com/">Long link </$text>' +
  117. '<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text>' +
  118. '<$text bold="true">ld</$text></paragraph>' );
  119. } );
  120. it( 'pastes inside another link element', () => {
  121. setData( editor.model, '<paragraph>1<$text linkHref="#test">tes[]t</$text>2</paragraph>' );
  122. expectPaste( editor, twoLine, '<paragraph>1<$text linkHref="#test">tes</$text>' +
  123. '<$text linkHref="https://cksource.com/">Long link </$text>' +
  124. '<softBreak></softBreak><$text linkHref="https://cksource.com/">WITH spaces[]</$text>' +
  125. '<$text linkHref="#test">t</$text>2</paragraph>' );
  126. } );
  127. } );
  128. } );