|
|
@@ -10,6 +10,7 @@ import { createNativeFileMock, AdapterMock } from './_utils/mocks';
|
|
|
import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
import Image from '@ckeditor/ckeditor5-image/src/image/imageengine';
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
+import buildModelConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildmodelconverter';
|
|
|
|
|
|
describe( 'ImageUploadCommand', () => {
|
|
|
let editor, command, adapterMock, document, fileRepository;
|
|
|
@@ -40,13 +41,38 @@ describe( 'ImageUploadCommand', () => {
|
|
|
it( 'should insert image', () => {
|
|
|
const file = createNativeFileMock();
|
|
|
setModelData( document, '<paragraph>foo[]</paragraph>' );
|
|
|
+
|
|
|
command._doExecute( { file } );
|
|
|
|
|
|
const id = fileRepository.getLoader( file ).id;
|
|
|
-
|
|
|
expect( getModelData( document ) ).to.equal( `<image uploadId="${ id }"></image><paragraph>foo[]</paragraph>` );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should insert image after other image', () => {
|
|
|
+ const file = createNativeFileMock();
|
|
|
+ setModelData( document, '[<image src="image.png"></image>]' );
|
|
|
+
|
|
|
+ command._doExecute( { file } );
|
|
|
+
|
|
|
+ const id = fileRepository.getLoader( file ).id;
|
|
|
+ expect( getModelData( document ) ).to.equal( `[<image src="image.png"></image>]<image uploadId="${ id }"></image>` );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should not insert image when proper insert position cannot be found', () => {
|
|
|
+ const file = createNativeFileMock();
|
|
|
+ document.schema.registerItem( 'other' );
|
|
|
+ document.schema.allow( { name: 'other', inside: '$root' } );
|
|
|
+ buildModelConverter().for( editor.editing.modelToView )
|
|
|
+ .fromElement( 'other' )
|
|
|
+ .toElement( 'span' );
|
|
|
+
|
|
|
+ setModelData( document, '<other>[]</other>' );
|
|
|
+
|
|
|
+ command._doExecute( { file } );
|
|
|
+
|
|
|
+ expect( getModelData( document ) ).to.equal( '<other>[]</other>' );
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should not insert non-image', () => {
|
|
|
const file = createNativeFileMock();
|
|
|
file.type = 'audio/mpeg3';
|