|
|
@@ -25,11 +25,11 @@ describe( 'HeadingCommand', () => {
|
|
|
commands = {};
|
|
|
schema = document.schema;
|
|
|
|
|
|
- editor.commands.set( 'paragraph', new ParagraphCommand( editor ) );
|
|
|
+ editor.commands.add( 'paragraph', new ParagraphCommand( editor ) );
|
|
|
schema.registerItem( 'paragraph', '$block' );
|
|
|
|
|
|
for ( const option of options ) {
|
|
|
- commands[ option.modelElement ] = new HeadingCommand( editor, option );
|
|
|
+ commands[ option.modelElement ] = new HeadingCommand( editor, option.modelElement );
|
|
|
schema.registerItem( option.modelElement, '$block' );
|
|
|
}
|
|
|
|
|
|
@@ -47,18 +47,10 @@ describe( 'HeadingCommand', () => {
|
|
|
}
|
|
|
} );
|
|
|
|
|
|
- describe( 'basic properties', () => {
|
|
|
- for ( const option of options ) {
|
|
|
- test( option );
|
|
|
- }
|
|
|
-
|
|
|
- function test( { modelElement, viewElement, title } ) {
|
|
|
- it( `are set for option.modelElement = ${ modelElement }`, () => {
|
|
|
- expect( commands[ modelElement ].modelElement ).to.equal( modelElement );
|
|
|
- expect( commands[ modelElement ].viewElement ).to.equal( viewElement );
|
|
|
- expect( commands[ modelElement ].title ).to.equal( title );
|
|
|
- } );
|
|
|
- }
|
|
|
+ describe( 'modelElement', () => {
|
|
|
+ it( 'is set', () => {
|
|
|
+ expect( commands.heading1.modelElement ).to.equal( 'heading1' );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'value', () => {
|
|
|
@@ -92,7 +84,7 @@ describe( 'HeadingCommand', () => {
|
|
|
expect( commands[ modelElement ].value ).to.be.false;
|
|
|
} );
|
|
|
|
|
|
- it( 'should be refreshed after calling refreshValue()', () => {
|
|
|
+ it( 'should be refreshed after calling refresh()', () => {
|
|
|
const command = commands[ modelElement ];
|
|
|
setData( document, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
|
|
|
const element = document.getRoot().getChild( 1 );
|
|
|
@@ -101,23 +93,48 @@ describe( 'HeadingCommand', () => {
|
|
|
document.selection.setRanges( [ Range.createIn( element ) ] );
|
|
|
|
|
|
expect( command.value ).to.be.true;
|
|
|
- command.refreshValue();
|
|
|
+ command.refresh();
|
|
|
expect( command.value ).to.be.false;
|
|
|
} );
|
|
|
}
|
|
|
} );
|
|
|
|
|
|
- describe( '_doExecute', () => {
|
|
|
+ describe( 'execute()', () => {
|
|
|
it( 'should update value after execution', () => {
|
|
|
const command = commands.heading1;
|
|
|
|
|
|
setData( document, '<paragraph>[]</paragraph>' );
|
|
|
- command._doExecute();
|
|
|
+ command.execute();
|
|
|
|
|
|
expect( getData( document ) ).to.equal( '<heading1>[]</heading1>' );
|
|
|
expect( command.value ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
+ // https://github.com/ckeditor/ckeditor5-heading/issues/73
|
|
|
+ it( 'should not rename blocks which cannot become headings', () => {
|
|
|
+ document.schema.registerItem( 'restricted' );
|
|
|
+ document.schema.allow( { name: 'restricted', inside: '$root' } );
|
|
|
+ document.schema.disallow( { name: 'heading1', inside: 'restricted' } );
|
|
|
+
|
|
|
+ document.schema.registerItem( 'fooBlock', '$block' );
|
|
|
+ document.schema.allow( { name: 'fooBlock', inside: 'restricted' } );
|
|
|
+
|
|
|
+ setData(
|
|
|
+ document,
|
|
|
+ '<paragraph>a[bc</paragraph>' +
|
|
|
+ '<restricted><fooBlock></fooBlock></restricted>' +
|
|
|
+ '<paragraph>de]f</paragraph>'
|
|
|
+ );
|
|
|
+
|
|
|
+ commands.heading1.execute();
|
|
|
+
|
|
|
+ expect( getData( document ) ).to.equal(
|
|
|
+ '<heading1>a[bc</heading1>' +
|
|
|
+ '<restricted><fooBlock></fooBlock></restricted>' +
|
|
|
+ '<heading1>de]f</heading1>'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'custom options', () => {
|
|
|
it( 'should use provided batch', () => {
|
|
|
const batch = editor.document.batch();
|
|
|
@@ -127,7 +144,7 @@ describe( 'HeadingCommand', () => {
|
|
|
|
|
|
expect( batch.deltas.length ).to.equal( 0 );
|
|
|
|
|
|
- command._doExecute( { batch } );
|
|
|
+ command.execute( { batch } );
|
|
|
|
|
|
expect( batch.deltas.length ).to.be.above( 0 );
|
|
|
} );
|
|
|
@@ -140,7 +157,7 @@ describe( 'HeadingCommand', () => {
|
|
|
|
|
|
expect( batch.deltas.length ).to.equal( 0 );
|
|
|
|
|
|
- command._doExecute( { batch } );
|
|
|
+ command.execute( { batch } );
|
|
|
|
|
|
expect( batch.deltas.length ).to.be.above( 0 );
|
|
|
} );
|
|
|
@@ -158,7 +175,7 @@ describe( 'HeadingCommand', () => {
|
|
|
const command = commands.heading1;
|
|
|
|
|
|
setData( document, '<heading1>foo[]bar</heading1>' );
|
|
|
- command._doExecute();
|
|
|
+ command.execute();
|
|
|
|
|
|
expect( getData( document ) ).to.equal( '<paragraph>foo[]bar</paragraph>' );
|
|
|
} );
|
|
|
@@ -168,7 +185,7 @@ describe( 'HeadingCommand', () => {
|
|
|
schema.allow( { name: '$text', inside: 'inlineImage' } );
|
|
|
|
|
|
setData( document, '<paragraph><inlineImage>foo[]</inlineImage>bar</paragraph>' );
|
|
|
- commands.heading1._doExecute();
|
|
|
+ commands.heading1.execute();
|
|
|
|
|
|
expect( getData( document ) ).to.equal( '<heading1><inlineImage>foo[]</inlineImage>bar</heading1>' );
|
|
|
} );
|
|
|
@@ -176,7 +193,7 @@ describe( 'HeadingCommand', () => {
|
|
|
function test( from, to ) {
|
|
|
it( `converts ${ from.modelElement } to ${ to.modelElement } on collapsed selection`, () => {
|
|
|
setData( document, `<${ from.modelElement }>foo[]bar</${ from.modelElement }>` );
|
|
|
- commands[ to.modelElement ]._doExecute();
|
|
|
+ commands[ to.modelElement ].execute();
|
|
|
|
|
|
expect( getData( document ) ).to.equal( `<${ to.modelElement }>foo[]bar</${ to.modelElement }>` );
|
|
|
} );
|
|
|
@@ -193,7 +210,7 @@ describe( 'HeadingCommand', () => {
|
|
|
|
|
|
it( 'converts all elements where selection is applied', () => {
|
|
|
setData( document, '<heading1>foo[</heading1><heading2>bar</heading2><heading3>]baz</heading3>' );
|
|
|
- commands.heading3._doExecute();
|
|
|
+ commands.heading3.execute();
|
|
|
|
|
|
expect( getData( document ) ).to.equal(
|
|
|
'<heading3>foo[</heading3><heading3>bar</heading3><heading3>]baz</heading3>'
|
|
|
@@ -202,7 +219,7 @@ describe( 'HeadingCommand', () => {
|
|
|
|
|
|
it( 'resets to default value all elements with same option', () => {
|
|
|
setData( document, '<heading1>foo[</heading1><heading1>bar</heading1><heading2>baz</heading2>]' );
|
|
|
- commands.heading1._doExecute();
|
|
|
+ commands.heading1.execute();
|
|
|
|
|
|
expect( getData( document ) ).to.equal(
|
|
|
'<paragraph>foo[</paragraph><paragraph>bar</paragraph><heading2>baz</heading2>]'
|
|
|
@@ -216,7 +233,7 @@ describe( 'HeadingCommand', () => {
|
|
|
`<${ fromElement }>foo[bar</${ fromElement }><${ fromElement }>baz]qux</${ fromElement }>`
|
|
|
);
|
|
|
|
|
|
- commands[ toElement ]._doExecute();
|
|
|
+ commands[ toElement ].execute();
|
|
|
|
|
|
expect( getData( document ) ).to.equal(
|
|
|
`<${ toElement }>foo[bar</${ toElement }><${ toElement }>baz]qux</${ toElement }>`
|