|
|
@@ -8,7 +8,7 @@ import HeadingCommand from '../src/headingcommand';
|
|
|
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
|
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
-const formats = [
|
|
|
+const options = [
|
|
|
{ id: 'paragraph', element: 'p', default: true },
|
|
|
{ id: 'heading1', element: 'h2' },
|
|
|
{ id: 'heading2', element: 'h3' },
|
|
|
@@ -21,17 +21,17 @@ describe( 'HeadingCommand', () => {
|
|
|
beforeEach( () => {
|
|
|
return ModelTestEditor.create( {
|
|
|
heading: {
|
|
|
- defaultFormatId: 'paragraph'
|
|
|
+ defaultOptionId: 'paragraph'
|
|
|
}
|
|
|
} )
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
document = editor.document;
|
|
|
- command = new HeadingCommand( editor, formats );
|
|
|
+ command = new HeadingCommand( editor, options );
|
|
|
schema = document.schema;
|
|
|
|
|
|
- for ( let format of formats ) {
|
|
|
- schema.registerItem( format.id, '$block' );
|
|
|
+ for ( let option of options ) {
|
|
|
+ schema.registerItem( option.id, '$block' );
|
|
|
}
|
|
|
|
|
|
root = document.getRoot();
|
|
|
@@ -43,34 +43,34 @@ describe( 'HeadingCommand', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'value', () => {
|
|
|
- for ( let format of formats ) {
|
|
|
- test( format );
|
|
|
+ for ( let option of options ) {
|
|
|
+ test( option );
|
|
|
}
|
|
|
|
|
|
- function test( format ) {
|
|
|
- it( `equals ${ format.id } when collapsed selection is placed inside ${ format.id } element`, () => {
|
|
|
- setData( document, `<${ format.id }>foobar</${ format.id }>` );
|
|
|
+ function test( option ) {
|
|
|
+ it( `equals ${ option.id } when collapsed selection is placed inside ${ option.id } element`, () => {
|
|
|
+ setData( document, `<${ option.id }>foobar</${ option.id }>` );
|
|
|
const element = root.getChild( 0 );
|
|
|
document.selection.addRange( Range.createFromParentsAndOffsets( element, 3, element, 3 ) );
|
|
|
|
|
|
- expect( command.value ).to.equal( format );
|
|
|
+ expect( command.value ).to.equal( option );
|
|
|
} );
|
|
|
}
|
|
|
|
|
|
- it( 'should be equal to defaultFormat if format has not been found', () => {
|
|
|
+ it( 'should be equal to defaultOption if option has not been found', () => {
|
|
|
schema.registerItem( 'div', '$block' );
|
|
|
setData( document, '<div>xyz</div>' );
|
|
|
const element = root.getChild( 0 );
|
|
|
document.selection.addRange( Range.createFromParentsAndOffsets( element, 1, element, 1 ) );
|
|
|
|
|
|
- expect( command.value ).to.equal( command.defaultFormat );
|
|
|
+ expect( command.value ).to.equal( command.defaultOption );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( '_doExecute', () => {
|
|
|
it( 'should update value after execution', () => {
|
|
|
setData( document, '<paragraph>[]</paragraph>' );
|
|
|
- command._doExecute( { formatId: 'heading1' } );
|
|
|
+ command._doExecute( { id: 'heading1' } );
|
|
|
|
|
|
expect( getData( document ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
expect( command.value ).to.be.object;
|
|
|
@@ -92,11 +92,11 @@ describe( 'HeadingCommand', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'collapsed selection', () => {
|
|
|
- let convertTo = formats[ formats.length - 1 ];
|
|
|
+ let convertTo = options[ options.length - 1 ];
|
|
|
|
|
|
- for ( let format of formats ) {
|
|
|
- test( format, convertTo );
|
|
|
- convertTo = format;
|
|
|
+ for ( let option of options ) {
|
|
|
+ test( option, convertTo );
|
|
|
+ convertTo = option;
|
|
|
}
|
|
|
|
|
|
it( 'uses paragraph as default value', () => {
|
|
|
@@ -106,9 +106,9 @@ describe( 'HeadingCommand', () => {
|
|
|
expect( getData( document ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
- it( 'converts to default format when executed with already applied format', () => {
|
|
|
+ it( 'converts to default option when executed with already applied option', () => {
|
|
|
setData( document, '<heading1>foo[]bar</heading1>' );
|
|
|
- command._doExecute( { formatId: 'heading1' } );
|
|
|
+ command._doExecute( { id: 'heading1' } );
|
|
|
|
|
|
expect( getData( document ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
|
|
|
} );
|
|
|
@@ -118,7 +118,7 @@ describe( 'HeadingCommand', () => {
|
|
|
schema.allow( { name: '$text', inside: 'inlineImage' } );
|
|
|
|
|
|
setData( document, '<heading1><inlineImage>foo[]</inlineImage>bar</heading1>' );
|
|
|
- command._doExecute( { formatId: 'heading1' } );
|
|
|
+ command._doExecute( { id: 'heading1' } );
|
|
|
|
|
|
expect( getData( document ) ).to.equal( '<paragraph><inlineImage>foo[]</inlineImage>bar</paragraph>' );
|
|
|
} );
|
|
|
@@ -126,7 +126,7 @@ describe( 'HeadingCommand', () => {
|
|
|
function test( from, to ) {
|
|
|
it( `converts ${ from.id } to ${ to.id } on collapsed selection`, () => {
|
|
|
setData( document, `<${ from.id }>foo[]bar</${ from.id }>` );
|
|
|
- command._doExecute( { formatId: to.id } );
|
|
|
+ command._doExecute( { id: to.id } );
|
|
|
|
|
|
expect( getData( document ) ).to.equal( `<${ to.id }>foo[]bar</${ to.id }>` );
|
|
|
} );
|
|
|
@@ -134,25 +134,25 @@ describe( 'HeadingCommand', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'non-collapsed selection', () => {
|
|
|
- let convertTo = formats[ formats.length - 1 ];
|
|
|
+ let convertTo = options[ options.length - 1 ];
|
|
|
|
|
|
- for ( let format of formats ) {
|
|
|
- test( format, convertTo );
|
|
|
- convertTo = format;
|
|
|
+ for ( let option of options ) {
|
|
|
+ test( option, convertTo );
|
|
|
+ convertTo = option;
|
|
|
}
|
|
|
|
|
|
it( 'converts all elements where selection is applied', () => {
|
|
|
setData( document, '<heading1>foo[</heading1><heading2>bar</heading2><heading2>]baz</heading2>' );
|
|
|
- command._doExecute( { formatId: 'paragraph' } );
|
|
|
+ command._doExecute( { id: 'paragraph' } );
|
|
|
|
|
|
expect( getData( document ) ).to.equal(
|
|
|
'<paragraph>foo[</paragraph><paragraph>bar</paragraph><paragraph>]baz</paragraph>'
|
|
|
);
|
|
|
} );
|
|
|
|
|
|
- it( 'resets to default value all elements with same format', () => {
|
|
|
+ it( 'resets to default value all elements with same option', () => {
|
|
|
setData( document, '<heading1>foo[</heading1><heading1>bar</heading1><heading2>baz</heading2>]' );
|
|
|
- command._doExecute( { formatId: 'heading1' } );
|
|
|
+ command._doExecute( { id: 'heading1' } );
|
|
|
|
|
|
expect( getData( document ) ).to.equal(
|
|
|
'<paragraph>foo[</paragraph><paragraph>bar</paragraph><heading2>baz</heading2>]'
|
|
|
@@ -162,7 +162,7 @@ describe( 'HeadingCommand', () => {
|
|
|
function test( from, to ) {
|
|
|
it( `converts ${ from.id } to ${ to.id } on non-collapsed selection`, () => {
|
|
|
setData( document, `<${ from.id }>foo[bar</${ from.id }><${ from.id }>baz]qux</${ from.id }>` );
|
|
|
- command._doExecute( { formatId: to.id } );
|
|
|
+ command._doExecute( { id: to.id } );
|
|
|
|
|
|
expect( getData( document ) ).to.equal( `<${ to.id }>foo[bar</${ to.id }><${ to.id }>baz]qux</${ to.id }>` );
|
|
|
} );
|