|
@@ -74,7 +74,7 @@ describe( 'ImageUploadEngine', () => {
|
|
|
it( 'should execute imageUpload command when image is pasted', () => {
|
|
it( 'should execute imageUpload command when image is pasted', () => {
|
|
|
const spy = sinon.spy( editor, 'execute' );
|
|
const spy = sinon.spy( editor, 'execute' );
|
|
|
const fileMock = createNativeFileMock();
|
|
const fileMock = createNativeFileMock();
|
|
|
- const dataTransfer = new DataTransfer( { files: [ fileMock ] } );
|
|
|
|
|
|
|
+ const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
|
|
|
setModelData( doc, '<paragraph>[]foo</paragraph>' );
|
|
setModelData( doc, '<paragraph>[]foo</paragraph>' );
|
|
|
|
|
|
|
|
const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
|
|
const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
|
|
@@ -94,7 +94,7 @@ describe( 'ImageUploadEngine', () => {
|
|
|
it( 'should execute imageUpload command with an optimized position when image is pasted', () => {
|
|
it( 'should execute imageUpload command with an optimized position when image is pasted', () => {
|
|
|
const spy = sinon.spy( editor, 'execute' );
|
|
const spy = sinon.spy( editor, 'execute' );
|
|
|
const fileMock = createNativeFileMock();
|
|
const fileMock = createNativeFileMock();
|
|
|
- const dataTransfer = new DataTransfer( { files: [ fileMock ] } );
|
|
|
|
|
|
|
+ const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
|
|
|
setModelData( doc, '<paragraph>[]foo</paragraph>' );
|
|
setModelData( doc, '<paragraph>[]foo</paragraph>' );
|
|
|
|
|
|
|
|
const paragraph = doc.getRoot().getChild( 0 );
|
|
const paragraph = doc.getRoot().getChild( 0 );
|
|
@@ -115,7 +115,7 @@ describe( 'ImageUploadEngine', () => {
|
|
|
it( 'should execute imageUpload command when multiple files image are pasted', () => {
|
|
it( 'should execute imageUpload command when multiple files image are pasted', () => {
|
|
|
const spy = sinon.spy( editor, 'execute' );
|
|
const spy = sinon.spy( editor, 'execute' );
|
|
|
const files = [ createNativeFileMock(), createNativeFileMock() ];
|
|
const files = [ createNativeFileMock(), createNativeFileMock() ];
|
|
|
- const dataTransfer = new DataTransfer( { files } );
|
|
|
|
|
|
|
+ const dataTransfer = new DataTransfer( { files, types: [ 'Files' ] } );
|
|
|
setModelData( doc, '<paragraph>[]foo</paragraph>' );
|
|
setModelData( doc, '<paragraph>[]foo</paragraph>' );
|
|
|
|
|
|
|
|
const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
|
|
const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
|
|
@@ -143,7 +143,7 @@ describe( 'ImageUploadEngine', () => {
|
|
|
type: 'media/mp3',
|
|
type: 'media/mp3',
|
|
|
size: 1024
|
|
size: 1024
|
|
|
};
|
|
};
|
|
|
- const dataTransfer = new DataTransfer( { files: [ fileMock ] } );
|
|
|
|
|
|
|
+ const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
|
|
|
|
|
|
|
|
setModelData( doc, '<paragraph>foo[]</paragraph>' );
|
|
setModelData( doc, '<paragraph>foo[]</paragraph>' );
|
|
|
|
|
|
|
@@ -155,6 +155,46 @@ describe( 'ImageUploadEngine', () => {
|
|
|
sinon.assert.notCalled( spy );
|
|
sinon.assert.notCalled( spy );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should not execute imageUpload command when there is non-empty HTML content pasted', () => {
|
|
|
|
|
+ const spy = sinon.spy( editor, 'execute' );
|
|
|
|
|
+ const fileMock = createNativeFileMock();
|
|
|
|
|
+ const dataTransfer = new DataTransfer( {
|
|
|
|
|
+ files: [ fileMock ],
|
|
|
|
|
+ types: [ 'Files', 'text/html' ],
|
|
|
|
|
+ getData: type => type === 'text/html' ? '<p>SomeData</p>' : ''
|
|
|
|
|
+ } );
|
|
|
|
|
+ setModelData( doc, '<paragraph>[]foo</paragraph>' );
|
|
|
|
|
+
|
|
|
|
|
+ const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
|
|
|
|
|
+ const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
|
|
|
|
|
+
|
|
|
|
|
+ viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
|
|
|
|
|
+
|
|
|
|
|
+ sinon.assert.notCalled( spy );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ // https://github.com/ckeditor/ckeditor5-upload/issues/70
|
|
|
|
|
+ it( 'should not crash on browsers which do not implement DOMStringList as a child class of an Array', () => {
|
|
|
|
|
+ const typesDomStringListMock = {
|
|
|
|
|
+ length: 2,
|
|
|
|
|
+ '0': 'text/html',
|
|
|
|
|
+ '1': 'text/plain'
|
|
|
|
|
+ };
|
|
|
|
|
+ const dataTransfer = new DataTransfer( {
|
|
|
|
|
+ types: typesDomStringListMock,
|
|
|
|
|
+ getData: type => type === 'text/html' ? '<p>SomeData</p>' : 'SomeData'
|
|
|
|
|
+ } );
|
|
|
|
|
+ setModelData( doc, '<paragraph>[]foo</paragraph>' );
|
|
|
|
|
+
|
|
|
|
|
+ const targetRange = doc.selection.getFirstRange();
|
|
|
|
|
+ const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
|
|
|
|
|
+
|
|
|
|
|
+ viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
|
|
|
|
|
+
|
|
|
|
|
+ // Well, there's no clipboard plugin, so nothing happens.
|
|
|
|
|
+ expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should not convert image\'s uploadId attribute if is consumed already', () => {
|
|
it( 'should not convert image\'s uploadId attribute if is consumed already', () => {
|
|
|
editor.editing.modelToView.on( 'addAttribute:uploadId:image', ( evt, data, consumable ) => {
|
|
editor.editing.modelToView.on( 'addAttribute:uploadId:image', ( evt, data, consumable ) => {
|
|
|
consumable.consume( data.item, eventNameToConsumableType( evt.name ) );
|
|
consumable.consume( data.item, eventNameToConsumableType( evt.name ) );
|