/** * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ import AlignmentEditing from '../src/alignmentediting'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; import ImageCaptionEngine from '@ckeditor/ckeditor5-image/src/imagecaption/imagecaptionengine'; 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 AlignmentCommand from '../src/alignmentcommand'; describe( 'AlignmentEditing', () => { let editor, doc; beforeEach( () => { return VirtualTestEditor .create( { plugins: [ AlignmentEditing, Paragraph ] } ) .then( newEditor => { editor = newEditor; doc = editor.document; } ); } ); afterEach( () => { editor.destroy(); } ); it( 'adds alignment commands', () => { expect( editor.commands.get( 'alignLeft' ) ).to.be.instanceOf( AlignmentCommand ); expect( editor.commands.get( 'alignRight' ) ).to.be.instanceOf( AlignmentCommand ); expect( editor.commands.get( 'alignCenter' ) ).to.be.instanceOf( AlignmentCommand ); expect( editor.commands.get( 'alignJustify' ) ).to.be.instanceOf( AlignmentCommand ); } ); it( 'allows for alignment in $blocks', () => { expect( doc.schema.check( { name: '$block', inside: '$root', attributes: 'alignment' } ) ).to.be.true; } ); describe( 'integration', () => { beforeEach( () => { return VirtualTestEditor .create( { plugins: [ AlignmentEditing, ImageCaptionEngine, Paragraph ] } ) .then( newEditor => { editor = newEditor; doc = editor.document; } ); } ); it( 'disallows for alignment in the catpion', () => { expect( doc.schema.check( { name: '$block', inside: 'figcaption', attributes: 'alignment' } ) ).to.be.true; } ); } ); describe( 'alignLeft', () => { it( 'adds converters to the data pipeline', () => { const data = '
x
'; editor.setData( data ); expect( getModelData( doc ) ).to.equal( 'x
' ); } ); } ); describe( 'alignCenter', () => { it( 'adds converters to the data pipeline', () => { const data = 'x
'; editor.setData( data ); expect( getModelData( doc ) ).to.equal( 'x
' ); } ); } ); describe( 'alignRight', () => { it( 'adds converters to the data pipeline', () => { const data = 'x
'; editor.setData( data ); expect( getModelData( doc ) ).to.equal( 'x
' ); } ); } ); describe( 'alignJustify', () => { it( 'adds converters to the data pipeline', () => { const data = 'x
'; editor.setData( data ); expect( getModelData( doc ) ).to.equal( 'x
' ); } ); } ); describe( 'should work with broken styles', () => { it( 'should ignore empty style', () => { const data = 'x
'; editor.setData( data ); expect( getModelData( doc ) ).to.equal( 'x
' ); } ); it( 'should ignore not known style', () => { const data = 'x
'; editor.setData( data ); expect( getModelData( doc ) ).to.equal( 'x
' ); } ); } ); } );