/** * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ /* globals document */ import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; import Heading from '@ckeditor/ckeditor5-heading/src/heading'; import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold'; import Link from '@ckeditor/ckeditor5-link/src/link'; import ShiftEnter from '@ckeditor/ckeditor5-enter/src/shiftenter'; import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; import { expectPaste } from '../../_utils/utils'; import withinText from '../../_data/link/within-text/input.word2016.html'; import combined from '../../_data/link/combined/input.word2016.html'; import twoLine from '../../_data/link/two-line/input.word2016.html'; describe( 'Link – integration', () => { let element, editor; before( () => { element = document.createElement( 'div' ); document.body.appendChild( element ); return ClassicTestEditor .create( element, { plugins: [ Clipboard, Paragraph, Heading, Bold, Link, ShiftEnter ] } ) .then( editorInstance => { editor = editorInstance; } ); } ); beforeEach( () => { setData( editor.model, '[]' ); } ); after( () => { editor.destroy(); element.remove(); } ); // Pastes: 'Regular link1' // Input same for: Chrome, Firefox and Edge. describe( 'within text', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, withinText, 'Regular ' + '<$text linkHref="https://ckeditor.com/">link1[]' ); } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, withinText, 'More Regular ' + '<$text linkHref="https://ckeditor.com/">link1[] text' ); } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, withinText, 'More Regular ' + '<$text linkHref="https://ckeditor.com/">link1[] text' ); } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text bold="true">Bo[]ld' ); expectPaste( editor, withinText, '<$text bold="true">Bo' + 'Regular <$text linkHref="https://ckeditor.com/">link1[]<$text bold="true">ld' ); } ); it( 'pastes inside another link element', () => { setData( editor.model, '1<$text linkHref="#test">tes[]t2' ); expectPaste( editor, withinText, '1<$text linkHref="#test">tes' + 'Regular <$text linkHref="https://ckeditor.com/">link1[]<$text linkHref="#test">t2' ); } ); } ); // Pastes: 'CKEditorCKSource 2' // Input same for: Chrome, Firefox and Edge. describe( 'combined', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, combined, '<$text linkHref="https://ckeditor.com/">CKEditor' + '<$text linkHref="https://cksource.com/">CKSource 2[]' ); } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, combined, 'More <$text linkHref="https://ckeditor.com/">CKEditor' + '<$text linkHref="https://cksource.com/">CKSource 2[] text' ); } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, combined, 'More <$text linkHref="https://ckeditor.com/">CKEditor' + '<$text linkHref="https://cksource.com/">CKSource 2[] text' ); } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text bold="true">Bo[]ld' ); expectPaste( editor, combined, '<$text bold="true">Bo' + '<$text linkHref="https://ckeditor.com/">CKEditor' + '<$text linkHref="https://cksource.com/">CKSource 2[]' + '<$text bold="true">ld' ); } ); it( 'pastes inside another link element', () => { setData( editor.model, '1<$text linkHref="#test">tes[]t2' ); expectPaste( editor, combined, '1<$text linkHref="#test">tes' + '<$text linkHref="https://ckeditor.com/">CKEditor' + '<$text linkHref="https://cksource.com/">CKSource 2[]' + '<$text linkHref="#test">t2' ); } ); } ); // Pastes: 'Long link
WITH spaces
' // Input same for: Chrome, Firefox and Edge. describe( 'two line', () => { it( 'pastes in the empty editor', () => { expectPaste( editor, twoLine, '<$text linkHref="https://cksource.com/">Long link ' + '<$text linkHref="https://cksource.com/">WITH spaces[]' ); } ); it( 'pastes in the paragraph', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, twoLine, 'More <$text linkHref="https://cksource.com/">Long link ' + '<$text linkHref="https://cksource.com/">WITH spaces[] text' ); } ); it( 'pastes in the different block context', () => { setData( editor.model, 'More [] text' ); expectPaste( editor, twoLine, 'More <$text linkHref="https://cksource.com/">Long link ' + '<$text linkHref="https://cksource.com/">WITH spaces[] text' ); } ); it( 'pastes in the inline styling context', () => { setData( editor.model, '<$text bold="true">Bo[]ld' ); expectPaste( editor, twoLine, '<$text bold="true">Bo' + '<$text linkHref="https://cksource.com/">Long link ' + '<$text linkHref="https://cksource.com/">WITH spaces[]' + '<$text bold="true">ld' ); } ); it( 'pastes inside another link element', () => { setData( editor.model, '1<$text linkHref="#test">tes[]t2' ); expectPaste( editor, twoLine, '1<$text linkHref="#test">tes' + '<$text linkHref="https://cksource.com/">Long link ' + '<$text linkHref="https://cksource.com/">WITH spaces[]' + '<$text linkHref="#test">t2' ); } ); } ); } );