/** * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ import ItalicEngine from 'ckeditor5-basic-styles/src/italicengine'; import VirtualTestEditor from 'ckeditor5-core/tests/_utils/virtualtesteditor'; import { getData as getModelData, setData as setModelData } from 'ckeditor5-engine/src/dev-utils/model'; import { getData as getViewData } from 'ckeditor5-engine/src/dev-utils/view'; import ToggleAttributeCommand from 'ckeditor5-core/src/command/toggleattributecommand'; describe( 'ItalicEngine', () => { let editor, doc; beforeEach( () => { return VirtualTestEditor.create( { plugins: [ ItalicEngine ] } ) .then( newEditor => { editor = newEditor; doc = editor.document; doc.schema.allow( { name: '$text', inside: '$root' } ); } ); } ); it( 'should be loaded', () => { expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine ); } ); it( 'should set proper schema rules', () => { expect( doc.schema.check( { name: '$inline', attributes: [ 'italic' ] } ) ).to.be.true; } ); describe( 'command', () => { it( 'should register italic command', () => { expect( editor.commands.has( 'italic' ) ).to.be.true; const command = editor.commands.get( 'italic' ); expect( command ).to.be.instanceOf( ToggleAttributeCommand ); expect( command ).to.have.property( 'attributeKey', 'italic' ); } ); } ); describe( 'data pipeline conversions', () => { it( 'should convert to italic attribute', () => { editor.setData( 'foobar' ); expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foobar' ); expect( editor.getData() ).to.equal( 'foobar' ); } ); it( 'should convert to italic attribute', () => { editor.setData( 'foobar' ); expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foobar' ); expect( editor.getData() ).to.equal( 'foobar' ); } ); it( 'should convert font-weight:italic to italic attribute', () => { editor.setData( 'foobar' ); expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text italic="true">foobar' ); expect( editor.getData() ).to.equal( 'foobar' ); } ); } ); describe( 'editing pipeline conversion', () => { it( 'should convert attribute', () => { setModelData( doc, '<$text italic="true">foobar' ); expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( 'foobar' ); } ); } ); } );