/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
import LinkEditing from '../src/linkediting';
import LinkCommand from '../src/linkcommand';
import UnlinkCommand from '../src/unlinkcommand';
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
import { isLinkElement } from '../src/utils';
import { downcastAttributeToElement } from '@ckeditor/ckeditor5-engine/src/conversion/downcast-converters';
describe( 'LinkEditing', () => {
let editor, model;
beforeEach( () => {
return VirtualTestEditor
.create( {
plugins: [ Paragraph, LinkEditing ]
} )
.then( newEditor => {
editor = newEditor;
model = editor.model;
} );
} );
it( 'should be loaded', () => {
expect( editor.plugins.get( LinkEditing ) ).to.be.instanceOf( LinkEditing );
} );
it( 'should set proper schema rules', () => {
expect( model.schema.checkAttribute( [ '$block', '$text' ], 'linkHref' ) ).to.be.true;
expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'linkHref' ) ).to.be.true;
expect( model.schema.checkAttribute( [ '$block' ], 'linkHref' ) ).to.be.false;
} );
describe( 'command', () => {
it( 'should register link command', () => {
const command = editor.commands.get( 'link' );
expect( command ).to.be.instanceOf( LinkCommand );
} );
it( 'should register unlink command', () => {
const command = editor.commands.get( 'unlink' );
expect( command ).to.be.instanceOf( UnlinkCommand );
} );
} );
describe( 'data pipeline conversions', () => {
it( 'should convert `` to `linkHref="url"` attribute', () => {
editor.setData( ' foobar foobar
foobar
' ); } ); // https://github.com/ckeditor/ckeditor5/issues/500 it( 'should not pick up ``', () => { editor.setData( 'foobar
' ); expect( getModelData( model, { withoutSelection: true } ) ) .to.equal( 'foobar
' ); expect( getModelData( model, { withoutSelection: true } ) ) .to.equal( 'foobar
' ); } ); } ); describe( 'editing pipeline conversion', () => { it( 'should convert attribute', () => { setModelData( model, 'foobar
' ); } ); it( 'should convert to link element instance', () => { setModelData( model, '