|
@@ -4,25 +4,19 @@
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
-import ImageStyleEngine from '../../src/imagestyle/imagestyleengine';
|
|
|
|
|
-import ImageEngine from '../../src/image/imageengine';
|
|
|
|
|
|
|
+import ImageStyleEditing from '../../src/imagestyle/imagestyleediting';
|
|
|
|
|
+import ImageEditing from '../../src/image/imageediting';
|
|
|
import ImageStyleCommand from '../../src/imagestyle/imagestylecommand';
|
|
import ImageStyleCommand from '../../src/imagestyle/imagestylecommand';
|
|
|
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
|
|
-import log from '@ckeditor/ckeditor5-utils/src/log';
|
|
|
|
|
|
|
+
|
|
|
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
|
|
|
|
|
|
|
|
-import fullWidthIcon from '@ckeditor/ckeditor5-core/theme/icons/object-full-width.svg';
|
|
|
|
|
-import leftIcon from '@ckeditor/ckeditor5-core/theme/icons/object-left.svg';
|
|
|
|
|
-import centerIcon from '@ckeditor/ckeditor5-core/theme/icons/object-center.svg';
|
|
|
|
|
-import rightIcon from '@ckeditor/ckeditor5-core/theme/icons/object-right.svg';
|
|
|
|
|
-
|
|
|
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
|
|
|
|
|
|
testUtils.createSinonSandbox();
|
|
testUtils.createSinonSandbox();
|
|
|
|
|
|
|
|
-describe( 'ImageStyleEngine', () => {
|
|
|
|
|
- let editor, plugin, model, document, viewDocument;
|
|
|
|
|
|
|
+describe( 'ImageStyleEditing', () => {
|
|
|
|
|
+ let editor, model, document, viewDocument;
|
|
|
|
|
|
|
|
afterEach( () => {
|
|
afterEach( () => {
|
|
|
editor.destroy();
|
|
editor.destroy();
|
|
@@ -32,7 +26,7 @@ describe( 'ImageStyleEngine', () => {
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
return VirtualTestEditor
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
.create( {
|
|
|
- plugins: [ ImageStyleEngine ],
|
|
|
|
|
|
|
+ plugins: [ ImageStyleEditing ],
|
|
|
} )
|
|
} )
|
|
|
.then( newEditor => {
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
editor = newEditor;
|
|
@@ -40,11 +34,11 @@ describe( 'ImageStyleEngine', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should be loaded', () => {
|
|
it( 'should be loaded', () => {
|
|
|
- expect( editor.plugins.get( ImageStyleEngine ) ).to.be.instanceOf( ImageStyleEngine );
|
|
|
|
|
|
|
+ expect( editor.plugins.get( ImageStyleEditing ) ).to.be.instanceOf( ImageStyleEditing );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should load image engine', () => {
|
|
|
|
|
- expect( editor.plugins.get( ImageEngine ) ).to.be.instanceOf( ImageEngine );
|
|
|
|
|
|
|
+ it( 'should load image editing', () => {
|
|
|
|
|
+ expect( editor.plugins.get( ImageEditing ) ).to.be.instanceOf( ImageEditing );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
@@ -52,7 +46,7 @@ describe( 'ImageStyleEngine', () => {
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
return VirtualTestEditor
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
.create( {
|
|
|
- plugins: [ ImageStyleEngine ],
|
|
|
|
|
|
|
+ plugins: [ ImageStyleEditing ],
|
|
|
image: {
|
|
image: {
|
|
|
styles: [
|
|
styles: [
|
|
|
{ name: 'fullStyle', title: 'foo', icon: 'object-center', isDefault: true },
|
|
{ name: 'fullStyle', title: 'foo', icon: 'object-center', isDefault: true },
|
|
@@ -72,7 +66,7 @@ describe( 'ImageStyleEngine', () => {
|
|
|
it( 'should define image.styles config', () => {
|
|
it( 'should define image.styles config', () => {
|
|
|
return VirtualTestEditor
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
.create( {
|
|
|
- plugins: [ ImageStyleEngine ]
|
|
|
|
|
|
|
+ plugins: [ ImageStyleEditing ]
|
|
|
} )
|
|
} )
|
|
|
.then( newEditor => {
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
editor = newEditor;
|
|
@@ -263,11 +257,11 @@ describe( 'ImageStyleEngine', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'imageStyles()', () => {
|
|
|
|
|
|
|
+ describe( 'config', () => {
|
|
|
it( 'should fall back to defaults when no image.styles', () => {
|
|
it( 'should fall back to defaults when no image.styles', () => {
|
|
|
return VirtualTestEditor
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
.create( {
|
|
|
- plugins: [ ImageStyleEngine ]
|
|
|
|
|
|
|
+ plugins: [ ImageStyleEditing ]
|
|
|
} )
|
|
} )
|
|
|
.then( newEditor => {
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
editor = newEditor;
|
|
@@ -279,7 +273,7 @@ describe( 'ImageStyleEngine', () => {
|
|
|
it( 'should not alter the image.styles config', () => {
|
|
it( 'should not alter the image.styles config', () => {
|
|
|
return VirtualTestEditor
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
.create( {
|
|
|
- plugins: [ ImageStyleEngine ],
|
|
|
|
|
|
|
+ plugins: [ ImageStyleEditing ],
|
|
|
image: {
|
|
image: {
|
|
|
styles: [
|
|
styles: [
|
|
|
'imageStyleSide'
|
|
'imageStyleSide'
|
|
@@ -296,7 +290,7 @@ describe( 'ImageStyleEngine', () => {
|
|
|
it( 'should not alter object definitions in the image.styles config', () => {
|
|
it( 'should not alter object definitions in the image.styles config', () => {
|
|
|
return VirtualTestEditor
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
.create( {
|
|
|
- plugins: [ ImageStyleEngine ],
|
|
|
|
|
|
|
+ plugins: [ ImageStyleEditing ],
|
|
|
image: {
|
|
image: {
|
|
|
styles: [
|
|
styles: [
|
|
|
{ name: 'imageStyleSide' }
|
|
{ name: 'imageStyleSide' }
|
|
@@ -309,187 +303,5 @@ describe( 'ImageStyleEngine', () => {
|
|
|
expect( newEditor.config.get( 'image.styles' ) ).to.deep.equal( [ { name: 'imageStyleSide' } ] );
|
|
expect( newEditor.config.get( 'image.styles' ) ).to.deep.equal( [ { name: 'imageStyleSide' } ] );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
-
|
|
|
|
|
- it( 'should cache the styles', () => {
|
|
|
|
|
- return VirtualTestEditor
|
|
|
|
|
- .create( {
|
|
|
|
|
- plugins: [ ImageStyleEngine ]
|
|
|
|
|
- } )
|
|
|
|
|
- .then( newEditor => {
|
|
|
|
|
- editor = newEditor;
|
|
|
|
|
- plugin = editor.plugins.get( ImageStyleEngine );
|
|
|
|
|
-
|
|
|
|
|
- expect( plugin.imageStyles ).to.equal( plugin.imageStyles );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- describe( 'object format', () => {
|
|
|
|
|
- beforeEach( () => {
|
|
|
|
|
- class TranslationMock extends Plugin {
|
|
|
|
|
- init() {
|
|
|
|
|
- sinon.stub( this.editor, 't' ).returns( 'Default translation' );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return VirtualTestEditor
|
|
|
|
|
- .create( {
|
|
|
|
|
- plugins: [ TranslationMock, ImageStyleEngine ],
|
|
|
|
|
- image: {
|
|
|
|
|
- styles: [
|
|
|
|
|
- // Custom user styles.
|
|
|
|
|
- { name: 'foo', title: 'foo', icon: 'custom', isDefault: true, className: 'foo-class' },
|
|
|
|
|
- { name: 'bar', title: 'bar', icon: 'right', className: 'bar-class' },
|
|
|
|
|
- { name: 'baz', title: 'Side image', icon: 'custom', className: 'baz-class' },
|
|
|
|
|
-
|
|
|
|
|
- // Customized default styles.
|
|
|
|
|
- { name: 'imageStyleFull', icon: 'left', title: 'Custom title' }
|
|
|
|
|
- ]
|
|
|
|
|
- }
|
|
|
|
|
- } )
|
|
|
|
|
- .then( newEditor => {
|
|
|
|
|
- editor = newEditor;
|
|
|
|
|
- plugin = editor.plugins.get( ImageStyleEngine );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should pass through if #name not found in default styles', () => {
|
|
|
|
|
- expect( plugin.imageStyles[ 0 ] ).to.deep.equal( {
|
|
|
|
|
- name: 'foo',
|
|
|
|
|
- title: 'foo',
|
|
|
|
|
- icon: 'custom',
|
|
|
|
|
- isDefault: true,
|
|
|
|
|
- className: 'foo-class'
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should use one of default icons if #icon matches', () => {
|
|
|
|
|
- expect( plugin.imageStyles[ 1 ].icon ).to.equal( ImageStyleEngine.defaultIcons.right );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should use one of default translations if #title matches', () => {
|
|
|
|
|
- expect( plugin.imageStyles[ 2 ].title ).to.deep.equal( 'Default translation' );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should extend one of default styles if #name matches', () => {
|
|
|
|
|
- expect( plugin.imageStyles[ 3 ] ).to.deep.equal( {
|
|
|
|
|
- name: 'imageStyleFull',
|
|
|
|
|
- title: 'Custom title',
|
|
|
|
|
- icon: ImageStyleEngine.defaultIcons.left,
|
|
|
|
|
- isDefault: true
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- describe( 'string format', () => {
|
|
|
|
|
- it( 'should use one of default styles if #name matches', () => {
|
|
|
|
|
- return VirtualTestEditor
|
|
|
|
|
- .create( {
|
|
|
|
|
- plugins: [ ImageStyleEngine ],
|
|
|
|
|
- image: {
|
|
|
|
|
- styles: [ 'imageStyleFull' ]
|
|
|
|
|
- }
|
|
|
|
|
- } )
|
|
|
|
|
- .then( newEditor => {
|
|
|
|
|
- editor = newEditor;
|
|
|
|
|
- plugin = editor.plugins.get( ImageStyleEngine );
|
|
|
|
|
- expect( plugin.imageStyles[ 0 ] ).to.deep.equal( ImageStyleEngine.defaultStyles.imageStyleFull );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- it( 'should warn if a #name not found in default styles', () => {
|
|
|
|
|
- testUtils.sinon.stub( log, 'warn' );
|
|
|
|
|
-
|
|
|
|
|
- return VirtualTestEditor
|
|
|
|
|
- .create( {
|
|
|
|
|
- plugins: [ ImageStyleEngine ],
|
|
|
|
|
- image: {
|
|
|
|
|
- styles: [ 'foo' ]
|
|
|
|
|
- }
|
|
|
|
|
- } )
|
|
|
|
|
- .then( newEditor => {
|
|
|
|
|
- editor = newEditor;
|
|
|
|
|
- plugin = editor.plugins.get( ImageStyleEngine );
|
|
|
|
|
-
|
|
|
|
|
- expect( plugin.imageStyles[ 0 ] ).to.deep.equal( {
|
|
|
|
|
- name: 'foo'
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- sinon.assert.calledOnce( log.warn );
|
|
|
|
|
- sinon.assert.calledWithExactly( log.warn,
|
|
|
|
|
- sinon.match( /^image-style-not-found/ ),
|
|
|
|
|
- { name: 'foo' }
|
|
|
|
|
- );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- describe( 'localizedDefaultStylesTitles()', () => {
|
|
|
|
|
- it( 'should return localized titles of default styles', () => {
|
|
|
|
|
- return VirtualTestEditor
|
|
|
|
|
- .create( {
|
|
|
|
|
- plugins: [ ImageStyleEngine ]
|
|
|
|
|
- } )
|
|
|
|
|
- .then( newEditor => {
|
|
|
|
|
- editor = newEditor;
|
|
|
|
|
- plugin = editor.plugins.get( ImageStyleEngine );
|
|
|
|
|
-
|
|
|
|
|
- expect( plugin.localizedDefaultStylesTitles ).to.deep.equal( {
|
|
|
|
|
- 'Full size image': 'Full size image',
|
|
|
|
|
- 'Side image': 'Side image',
|
|
|
|
|
- 'Left aligned image': 'Left aligned image',
|
|
|
|
|
- 'Centered image': 'Centered image',
|
|
|
|
|
- 'Right aligned image': 'Right aligned image'
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- describe( 'defaultStyles', () => {
|
|
|
|
|
- it( 'should be defined', () => {
|
|
|
|
|
- expect( ImageStyleEngine.defaultStyles ).to.deep.equal( {
|
|
|
|
|
- imageStyleFull: {
|
|
|
|
|
- name: 'imageStyleFull',
|
|
|
|
|
- title: 'Full size image',
|
|
|
|
|
- icon: fullWidthIcon,
|
|
|
|
|
- isDefault: true
|
|
|
|
|
- },
|
|
|
|
|
- imageStyleSide: {
|
|
|
|
|
- name: 'imageStyleSide',
|
|
|
|
|
- title: 'Side image',
|
|
|
|
|
- icon: rightIcon,
|
|
|
|
|
- className: 'image-style-side'
|
|
|
|
|
- },
|
|
|
|
|
- imageStyleAlignLeft: {
|
|
|
|
|
- name: 'imageStyleAlignLeft',
|
|
|
|
|
- title: 'Left aligned image',
|
|
|
|
|
- icon: leftIcon,
|
|
|
|
|
- className: 'image-style-align-left'
|
|
|
|
|
- },
|
|
|
|
|
- imageStyleAlignCenter: {
|
|
|
|
|
- name: 'imageStyleAlignCenter',
|
|
|
|
|
- title: 'Centered image',
|
|
|
|
|
- icon: centerIcon,
|
|
|
|
|
- className: 'image-style-align-center'
|
|
|
|
|
- },
|
|
|
|
|
- imageStyleAlignRight: {
|
|
|
|
|
- name: 'imageStyleAlignRight',
|
|
|
|
|
- title: 'Right aligned image',
|
|
|
|
|
- icon: rightIcon,
|
|
|
|
|
- className: 'image-style-align-right'
|
|
|
|
|
- }
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
- describe( 'defaultIcons', () => {
|
|
|
|
|
- it( 'should be defined', () => {
|
|
|
|
|
- expect( ImageStyleEngine.defaultIcons ).to.deep.equal( {
|
|
|
|
|
- full: fullWidthIcon,
|
|
|
|
|
- left: leftIcon,
|
|
|
|
|
- right: rightIcon,
|
|
|
|
|
- center: centerIcon,
|
|
|
|
|
- } );
|
|
|
|
|
- } );
|
|
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|