/** * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ import HeadingEngine from '/ckeditor5/heading/headingengine.js'; import Paragraph from '/ckeditor5/paragraph/paragraph.js'; import VirtualTestEditor from '/tests/core/_utils/virtualtesteditor.js'; import HeadingCommand from '/ckeditor5/heading/headingcommand.js'; import Enter from '/ckeditor5/enter/enter.js'; import { getData } from '/ckeditor5/engine/dev-utils/model.js'; describe( 'HeadingEngine', () => { let editor, document; beforeEach( () => { return VirtualTestEditor.create( { features: [ Enter, HeadingEngine ] } ) .then( newEditor => { editor = newEditor; document = editor.document; } ); } ); it( 'should be loaded', () => { expect( editor.plugins.get( HeadingEngine ) ).to.be.instanceOf( HeadingEngine ); } ); it( 'should load paragraph feature', () => { expect( editor.plugins.get( Paragraph ) ).to.be.instanceOf( Paragraph ); } ); it( 'should set proper schema rules', () => { expect( document.schema.hasItem( 'heading1' ) ).to.be.true; expect( document.schema.hasItem( 'heading2' ) ).to.be.true; expect( document.schema.hasItem( 'heading3' ) ).to.be.true; expect( document.schema.check( { name: 'heading1', inside: '$root' } ) ).to.be.true; expect( document.schema.check( { name: '$inline', inside: 'heading1' } ) ).to.be.true; expect( document.schema.check( { name: 'heading2', inside: '$root' } ) ).to.be.true; expect( document.schema.check( { name: '$inline', inside: 'heading2' } ) ).to.be.true; expect( document.schema.check( { name: 'heading3', inside: '$root' } ) ).to.be.true; expect( document.schema.check( { name: '$inline', inside: 'heading3' } ) ).to.be.true; } ); it( 'should register format command', () => { expect( editor.commands.has( 'heading' ) ).to.be.true; const command = editor.commands.get( 'heading' ); expect( command ).to.be.instanceOf( HeadingCommand ); } ); it( 'should convert heading1', () => { editor.setData( '

foobar

' ); expect( getData( document, { withoutSelection: true } ) ).to.equal( 'foobar' ); expect( editor.getData() ).to.equal( '

foobar

' ); } ); it( 'should convert heading2', () => { editor.setData( '

foobar

' ); expect( getData( document, { withoutSelection: true } ) ).to.equal( 'foobar' ); expect( editor.getData() ).to.equal( '

foobar

' ); } ); it( 'should convert heading3', () => { editor.setData( '

foobar

' ); expect( getData( document, { withoutSelection: true } ) ).to.equal( 'foobar' ); expect( editor.getData() ).to.equal( '

foobar

' ); } ); it( 'should make enter command insert a defaultFormat block if selection ended at the end of heading block', () => { editor.setData( '

foobar

' ); document.selection.collapse( document.getRoot().getChild( 0 ), 'end' ); editor.execute( 'enter' ); expect( getData( document ) ).to.equal( 'foobar[]' ); } ); it( 'should not alter enter command if selection not ended at the end of heading block', () => { // This test is to fill code coverage. editor.setData( '

foobar

' ); document.selection.collapse( document.getRoot().getChild( 0 ), 3 ); editor.execute( 'enter' ); expect( getData( document ) ).to.equal( 'foo[]bar' ); } ); } );