|
|
@@ -7,10 +7,8 @@ import HeadingEditing from '../src/headingediting';
|
|
|
import HeadingCommand from '../src/headingcommand';
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
import ParagraphCommand from '@ckeditor/ckeditor5-paragraph/src/paragraphcommand';
|
|
|
-import Conversion from '@ckeditor/ckeditor5-engine/src/conversion/conversion';
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
|
-import priorities from '@ckeditor/ckeditor5-utils/src/priorities';
|
|
|
import { getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
describe( 'HeadingEditing', () => {
|
|
|
@@ -76,7 +74,7 @@ describe( 'HeadingEditing', () => {
|
|
|
expect( editor.getData() ).to.equal( '<h4>foobar</h4>' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should convert h1 to heading1', () => {
|
|
|
+ it( 'should convert h1 to heading1 using default, low-priority converter', () => {
|
|
|
editor.setData( '<h1>foobar</h1>' );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true } ) ).to.equal( '<heading1>foobar</heading1>' );
|
|
|
@@ -127,34 +125,62 @@ describe( 'HeadingEditing', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'default h1 conversion', () => {
|
|
|
- let elementToElementSpy;
|
|
|
+ let addDefaultConversionSpy;
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
beforeEach( () => {
|
|
|
- elementToElementSpy = testUtils.sinon.spy( Conversion.prototype, 'elementToElement' );
|
|
|
+ addDefaultConversionSpy = testUtils.sinon.spy( HeadingEditing.prototype, '_addDefaultH1Conversion' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should define the default h1 to heading1 converter when heading.options is not specified', () => {
|
|
|
+ it( 'should define the default h1 to heading1 converter' +
|
|
|
+ 'when heading.options is not specified and apply it during conversions', () => {
|
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
|
plugins: [ HeadingEditing ]
|
|
|
} )
|
|
|
- .then( () => {
|
|
|
- expect( elementToElementSpy.calledWith( {
|
|
|
- model: 'heading1',
|
|
|
- view: 'h1',
|
|
|
- title: 'Heading 1',
|
|
|
- class: 'ck-heading_heading1',
|
|
|
- converterPriority: priorities.get( 'low' ) + 1
|
|
|
- } ) ).to.true;
|
|
|
+ .then( editor => {
|
|
|
+ expect( addDefaultConversionSpy.callCount ).to.equal( 1 );
|
|
|
+
|
|
|
+ editor.setData( '<h1>Foo</h1><h2>Bar</h2><p>Baz</p>' );
|
|
|
+
|
|
|
+ expect( getData( editor.model, { withoutSelection: true } ) )
|
|
|
+ .to.equal( '<heading1>Foo</heading1><heading1>Bar</heading1><paragraph>Baz</paragraph>' );
|
|
|
+
|
|
|
+ expect( editor.getData() ).to.equal( '<h2>Foo</h2><h2>Bar</h2><p>Baz</p>' );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should define the default h1 to heading1 converter' +
|
|
|
+ 'when heading.options is specified and apply it during conversions', () => {
|
|
|
+ const options = [
|
|
|
+ { model: 'heading1', view: 'h3' },
|
|
|
+ { model: 'heading2', view: 'h4' }
|
|
|
+ ];
|
|
|
+
|
|
|
+ return VirtualTestEditor
|
|
|
+ .create( {
|
|
|
+ plugins: [ HeadingEditing ],
|
|
|
+ heading: { options }
|
|
|
+ } )
|
|
|
+ .then( editor => {
|
|
|
+ expect( addDefaultConversionSpy.callCount ).to.equal( 1 );
|
|
|
+
|
|
|
+ editor.setData( '<h1>Foo</h1><h3>Bar</h3><h4>Baz</h4><h2>Bax</h2>' );
|
|
|
+
|
|
|
+ expect( getData( editor.model, { withoutSelection: true } ) )
|
|
|
+ .to.equal( '<heading1>Foo</heading1><heading1>Bar</heading1><heading2>Baz</heading2><paragraph>Bax</paragraph>' );
|
|
|
+
|
|
|
+ expect( editor.getData() ).to.equal( '<h3>Foo</h3><h3>Bar</h3><h4>Baz</h4><p>Bax</p>' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- it( 'should define the default h1 to heading1 converter when heading.options is specified', () => {
|
|
|
+ it( 'should define the default h1 to heading1 converter' +
|
|
|
+ 'when heading.options is specified with h1 but not apply it during conversions', () => {
|
|
|
const options = [
|
|
|
- { model: 'heading1', view: 'h3', title: 'User H3' },
|
|
|
- { model: 'heading2', view: 'h4', title: 'User H4' }
|
|
|
+ { model: 'heading1', view: 'h2' },
|
|
|
+ { model: 'heading2', view: 'h1' },
|
|
|
+ { model: 'heading3', view: 'h3' }
|
|
|
];
|
|
|
|
|
|
return VirtualTestEditor
|
|
|
@@ -162,14 +188,15 @@ describe( 'HeadingEditing', () => {
|
|
|
plugins: [ HeadingEditing ],
|
|
|
heading: { options }
|
|
|
} )
|
|
|
- .then( () => {
|
|
|
- expect( elementToElementSpy.calledWith( {
|
|
|
- model: 'heading1',
|
|
|
- view: 'h1',
|
|
|
- title: 'Heading 1',
|
|
|
- class: 'ck-heading_heading1',
|
|
|
- converterPriority: priorities.get( 'low' ) + 1
|
|
|
- } ) ).to.true;
|
|
|
+ .then( editor => {
|
|
|
+ expect( addDefaultConversionSpy.callCount ).to.equal( 1 );
|
|
|
+
|
|
|
+ editor.setData( '<h1>Foo</h1><h2>Bar</h2><h3>Baz</h3><h4>Bax</h4>' );
|
|
|
+
|
|
|
+ expect( getData( editor.model, { withoutSelection: true } ) )
|
|
|
+ .to.equal( '<heading2>Foo</heading2><heading1>Bar</heading1><heading3>Baz</heading3><paragraph>Bax</paragraph>' );
|
|
|
+
|
|
|
+ expect( editor.getData() ).to.equal( '<h1>Foo</h1><h2>Bar</h2><h3>Baz</h3><p>Bax</p>' );
|
|
|
} );
|
|
|
} );
|
|
|
} );
|