/**
* @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/">link$text>1[]' );
} );
it( 'pastes in the paragraph', () => {
setData( editor.model, 'More [] text' );
expectPaste( editor, withinText, 'More Regular ' +
'<$text linkHref="https://ckeditor.com/">link$text>1[] text' );
} );
it( 'pastes in the different block context', () => {
setData( editor.model, 'More [] text' );
expectPaste( editor, withinText, 'More Regular ' +
'<$text linkHref="https://ckeditor.com/">link$text>1[] text' );
} );
it( 'pastes in the inline styling context', () => {
setData( editor.model, '<$text bold="true">Bo[]ld$text>' );
expectPaste( editor, withinText, '<$text bold="true">Bo$text>' +
'Regular <$text linkHref="https://ckeditor.com/">link$text>1[]<$text bold="true">ld$text>' );
} );
it( 'pastes inside another link element', () => {
setData( editor.model, '1<$text linkHref="#test">tes[]t$text>2' );
expectPaste( editor, withinText, '1<$text linkHref="#test">tes$text>' +
'Regular <$text linkHref="https://ckeditor.com/">link$text>1[]<$text linkHref="#test">t$text>2' );
} );
} );
// 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>' +
'<$text linkHref="https://cksource.com/">CKSource$text> 2[]' );
} );
it( 'pastes in the paragraph', () => {
setData( editor.model, 'More [] text' );
expectPaste( editor, combined, 'More <$text linkHref="https://ckeditor.com/">CKEditor$text>' +
'<$text linkHref="https://cksource.com/">CKSource$text> 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>' +
'<$text linkHref="https://cksource.com/">CKSource$text> 2[] text' );
} );
it( 'pastes in the inline styling context', () => {
setData( editor.model, '<$text bold="true">Bo[]ld$text>' );
expectPaste( editor, combined, '<$text bold="true">Bo$text>' +
'<$text linkHref="https://ckeditor.com/">CKEditor$text>' +
'<$text linkHref="https://cksource.com/">CKSource$text> 2[]' +
'<$text bold="true">ld$text>' );
} );
it( 'pastes inside another link element', () => {
setData( editor.model, '1<$text linkHref="#test">tes[]t$text>2' );
expectPaste( editor, combined, '1<$text linkHref="#test">tes$text>' +
'<$text linkHref="https://ckeditor.com/">CKEditor$text>' +
'<$text linkHref="https://cksource.com/">CKSource$text> 2[]' +
'<$text linkHref="#test">t$text>2' );
} );
} );
// 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>' +
'<$text linkHref="https://cksource.com/">WITH spaces[]$text>' );
} );
it( 'pastes in the paragraph', () => {
setData( editor.model, 'More [] text' );
expectPaste( editor, twoLine, 'More <$text linkHref="https://cksource.com/">Long link $text>' +
'<$text linkHref="https://cksource.com/">WITH spaces[]$text> 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>' +
'<$text linkHref="https://cksource.com/">WITH spaces[]$text> text' );
} );
it( 'pastes in the inline styling context', () => {
setData( editor.model, '<$text bold="true">Bo[]ld$text>' );
expectPaste( editor, twoLine, '<$text bold="true">Bo$text>' +
'<$text linkHref="https://cksource.com/">Long link $text>' +
'<$text linkHref="https://cksource.com/">WITH spaces[]$text>' +
'<$text bold="true">ld$text>' );
} );
it( 'pastes inside another link element', () => {
setData( editor.model, '1<$text linkHref="#test">tes[]t$text>2' );
expectPaste( editor, twoLine, '1<$text linkHref="#test">tes$text>' +
'<$text linkHref="https://cksource.com/">Long link $text>' +
'<$text linkHref="https://cksource.com/">WITH spaces[]$text>' +
'<$text linkHref="#test">t$text>2' );
} );
} );
} );