|
|
@@ -4,24 +4,25 @@
|
|
|
*/
|
|
|
|
|
|
import ItalicEngine from '../src/italicengine';
|
|
|
+
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
+import ToggleAttributeCommand from '@ckeditor/ckeditor5-core/src/command/toggleattributecommand';
|
|
|
+
|
|
|
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 ToggleAttributeCommand from '@ckeditor/ckeditor5-core/src/command/toggleattributecommand';
|
|
|
|
|
|
describe( 'ItalicEngine', () => {
|
|
|
let editor, doc;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
return VirtualTestEditor.create( {
|
|
|
- plugins: [ ItalicEngine ]
|
|
|
+ plugins: [ Paragraph, ItalicEngine ]
|
|
|
} )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
|
|
|
doc = editor.document;
|
|
|
-
|
|
|
- doc.schema.allow( { name: '$text', inside: '$root' } );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
@@ -30,7 +31,7 @@ describe( 'ItalicEngine', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should set proper schema rules', () => {
|
|
|
- expect( doc.schema.check( { name: '$inline', attributes: [ 'italic' ] } ) ).to.be.true;
|
|
|
+ expect( doc.schema.check( { name: '$inline', attributes: [ 'italic' ], inside: '$block' } ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
describe( 'command', () => {
|
|
|
@@ -46,32 +47,38 @@ describe( 'ItalicEngine', () => {
|
|
|
|
|
|
describe( 'data pipeline conversions', () => {
|
|
|
it( 'should convert <em> to italic attribute', () => {
|
|
|
- editor.setData( '<em>foo</em>bar' );
|
|
|
+ editor.setData( '<p><em>foo</em>bar</p>' );
|
|
|
+
|
|
|
+ expect( getModelData( doc, { withoutSelection: true } ) )
|
|
|
+ .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
|
|
|
|
|
|
- expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foo</$text>bar' );
|
|
|
- expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
|
|
|
+ expect( editor.getData() ).to.equal( '<p><em>foo</em>bar</p>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should convert <i> to italic attribute', () => {
|
|
|
- editor.setData( '<i>foo</i>bar' );
|
|
|
+ editor.setData( '<p><i>foo</i>bar</p>' );
|
|
|
|
|
|
- expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foo</$text>bar' );
|
|
|
- expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
|
|
|
+ expect( getModelData( doc, { withoutSelection: true } ) )
|
|
|
+ .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
|
|
|
+
|
|
|
+ expect( editor.getData() ).to.equal( '<p><em>foo</em>bar</p>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should convert font-weight:italic to italic attribute', () => {
|
|
|
- editor.setData( '<span style="font-style: italic;">foo</span>bar' );
|
|
|
+ editor.setData( '<p><span style="font-style: italic;">foo</span>bar</p>' );
|
|
|
+
|
|
|
+ expect( getModelData( doc, { withoutSelection: true } ) )
|
|
|
+ .to.equal( '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
|
|
|
|
|
|
- expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foo</$text>bar' );
|
|
|
- expect( editor.getData() ).to.equal( '<em>foo</em>bar' );
|
|
|
+ expect( editor.getData() ).to.equal( '<p><em>foo</em>bar</p>' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'editing pipeline conversion', () => {
|
|
|
it( 'should convert attribute', () => {
|
|
|
- setModelData( doc, '<$text italic="true">foo</$text>bar' );
|
|
|
+ setModelData( doc, '<paragraph><$text italic="true">foo</$text>bar</paragraph>' );
|
|
|
|
|
|
- expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<em>foo</em>bar' );
|
|
|
+ expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p><em>foo</em>bar</p>' );
|
|
|
} );
|
|
|
} );
|
|
|
} );
|