/**
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
import Paragraph from '../src/paragraph';
import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
import UndoEngine from '@ckeditor/ckeditor5-undo/src/undoengine';
import HeadingEngine from '@ckeditor/ckeditor5-heading/src/headingengine';
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import {
getData as getModelData,
setData as setModelData
} from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { parse as parseView } from '@ckeditor/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;
const clipboard = editor.plugins.get( 'clipboard/clipboard' );
setModelData( doc, '[]' );
clipboard.fire( 'inputTransformation', {
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;
const clipboard = editor.plugins.get( 'clipboard/clipboard' );
setModelData( doc, '[]' );
clipboard.fire( 'inputTransformation', {
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;
const clipboard = editor.plugins.get( 'clipboard/clipboard' );
setModelData( doc, '[]' );
clipboard.fire( 'inputTransformation', {
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;
const clipboard = editor.plugins.get( 'clipboard/clipboard' );
setModelData( doc, '[]' );
clipboard.fire( 'inputTransformation', {
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;
const clipboard = editor.plugins.get( 'clipboard/clipboard' );
setModelData( doc, '[]' );
clipboard.fire( 'inputTransformation', {
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;
const clipboard = editor.plugins.get( 'clipboard/clipboard' );
setModelData( doc, '[]' );
clipboard.fire( 'inputTransformation', {
content: parseView( '' )
} );
expect( getModelData( doc ) ).to.equal(
'a' +
'b[]'
);
} );
} );
} );
describe( 'with undo', () => {
it( 'fixing empty roots should be transparent to undo', () => {
return VirtualTestEditor.create( {
plugins: [ Paragraph, UndoEngine ]
} )
.then( newEditor => {
const editor = newEditor;
const doc = editor.document;
const root = doc.getRoot();
// Selection is in , hence
expect( editor.getData() ).to.equal( '
' );
expect( editor.commands.get( 'undo' ).isEnabled ).to.be.false;
editor.setData( 'Foobar.
' );
doc.enqueueChanges( () => {
doc.batch().remove( root.getChild( 0 ) );
} );
expect( editor.getData() ).to.equal( '
' );
editor.execute( 'undo' );
expect( editor.getData() ).to.equal( 'Foobar.
' );
editor.execute( 'redo' );
expect( editor.getData() ).to.equal( '
' );
editor.execute( 'undo' );
expect( editor.getData() ).to.equal( 'Foobar.
' );
} );
} );
} );
} );