/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
import Paragraph from 'ckeditor5-paragraph/src/paragraph';
import Clipboard from 'ckeditor5-clipboard/src/clipboard';
import HeadingEngine from 'ckeditor5-heading/src/headingengine';
import VirtualTestEditor from 'ckeditor5-core/tests/_utils/virtualtesteditor';
import {
getData as getModelData,
setData as setModelData
} from 'ckeditor5-engine/src/dev-utils/model';
import { parse as parseView } from 'ckeditor5-engine/src/dev-utils/view';
describe( 'Paragraph feature – integration', () => {
describe( 'with clipboard', () => {
it( 'pastes h1+h2+p as p+p+p when heading feature is not present', () => {
return VirtualTestEditor.create( {
plugins: [ Paragraph, Clipboard ]
} )
.then( newEditor => {
const editor = newEditor;
const doc = editor.document;
setModelData( doc, '[]' );
editor.editing.view.fire( 'clipboardInput', {
content: parseView( '
foo
bar
bom
' )
} );
expect( getModelData( doc ) ).to.equal( 'foobarbom[]' );
} );
} );
// Explainer: the heading feature is configured to handle h2-h4 elements, so h1 has no handler.
it( 'pastes h1+h2+p as p+h2+p when heading feature is present', () => {
return VirtualTestEditor.create( {
plugins: [ Paragraph, Clipboard, HeadingEngine ]
} )
.then( newEditor => {
const editor = newEditor;
const doc = editor.document;
setModelData( doc, '[]' );
editor.editing.view.fire( 'clipboardInput', {
content: parseView( 'foo
bar
bom
' )
} );
expect( getModelData( doc ) ).to.equal( 'foobarbom[]' );
} );
} );
it( 'pastes ul>li+li as p+p when list feature is not present', () => {
return VirtualTestEditor.create( {
plugins: [ Paragraph, Clipboard ]
} )
.then( newEditor => {
const editor = newEditor;
const doc = editor.document;
setModelData( doc, '[]' );
editor.editing.view.fire( 'clipboardInput', {
content: parseView( '' )
} );
expect( getModelData( doc ) ).to.equal( 'foobar[]' );
} );
} );
// Check whether the paragraph feature doesn't breaking pasting such content by trying to
// handle the li element.
it( 'pastes ul>li>h2+h3+p as h2+h3+p when heading feature is present', () => {
return VirtualTestEditor.create( {
plugins: [ Paragraph, Clipboard, HeadingEngine ]
} )
.then( newEditor => {
const editor = newEditor;
const doc = editor.document;
setModelData( doc, '[]' );
editor.editing.view.fire( 'clipboardInput', {
content: parseView( '' )
} );
expect( getModelData( doc ) ).to.equal(
'x' +
'foobarbom' +
'x[]'
);
} );
} );
// See 'should convert ul>li>ul>li+li (in clipboard holder)' in clipboard.js.
it( 'pastes ul>li>ul>li+li', () => {
return VirtualTestEditor.create( {
plugins: [ Paragraph, Clipboard ]
} )
.then( newEditor => {
const editor = newEditor;
const doc = editor.document;
setModelData( doc, '[]' );
editor.editing.view.fire( 'clipboardInput', {
content: parseView( '' )
} );
expect( getModelData( doc ) ).to.equal(
'a' +
'b' +
'c[]'
);
} );
} );
// See 'should convert ul>li>p,text (in clipboard holder)' in clipboard.js.
it( 'pastes ul>li>p,text', () => {
return VirtualTestEditor.create( {
plugins: [ Paragraph, Clipboard ]
} )
.then( newEditor => {
const editor = newEditor;
const doc = editor.document;
setModelData( doc, '[]' );
editor.editing.view.fire( 'clipboardInput', {
content: parseView( '' )
} );
expect( getModelData( doc ) ).to.equal(
'a' +
'b[]'
);
} );
} );
} );
} );