Skip to content

Commit

Permalink
Unit test now tests that a custom image handler plugin receive files.
Browse files Browse the repository at this point in the history
A custom image handler plugin must be able to receive images being pasted or dropped when clipboard_handleImages option is false.
  • Loading branch information
FlowIT-JIT committed Sep 24, 2021
1 parent 80e19ab commit 607fa61
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions tests/plugins/clipboard/clipboardimagedisabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,32 @@
( function() {
'use strict';

var pasteCount = 0,
dropCount = 0;

CKEDITOR.plugins.add( 'customImagePasteHandlerPlugin', {
init: function( editor ) {
editor.on( 'paste', function( event ) {
if (event.data.dataTransfer.$.files.length === 1) {
pasteCount++;
}
} );
editor.on( 'drop', function( event ) {
if (event.data.dataTransfer.$.files.length === 1) {
dropCount++;
}
} );
}
} );

var originalFileReader = window.FileReader;

bender.editor = {
config: {
allowedContent: true,
language: 'en',
clipboard_handleImages: false
clipboard_handleImages: false,
extraPlugins: "customImagePasteHandlerPlugin"
}
};

Expand All @@ -35,24 +54,36 @@
FileReader.setFileMockType( 'image/png' );
FileReader.setReadResult( 'load' );

pasteCount = 0;
var assert = this.assert;

bender.tools.selection.setWithHtml( this.editor, '<p>Paste image here:{}</p>' );
this.assertPaste( {
type: 'image/png',
expected: '<p>Paste image here:^@</p>'
expected: '<p>Paste image here:^@</p>',
callback: function() {
assert(pasteCount === 1, "custom image handler plugin did not receive file");
}
} );
},

'test image and text paste from clipboard, only image suppressed': function() {
FileReader.setFileMockType( 'image/png' );
FileReader.setReadResult( 'load' );

pasteCount = 0;
var assert = this.assert;

bender.tools.selection.setWithHtml( this.editor, '<p>{}</p>' );
this.assertPaste( {
type: 'image/png',
expected: '<p><strong>Hello world^</strong>@</p><p></p>',
additionalData: [
{ type: 'text/html', data: '<strong>Hello world</strong>' }
]
],
callback: function() {
assert(pasteCount === 1, "custom image handler plugin did not receive file");
}
} );
},

Expand All @@ -64,6 +95,9 @@
FileReader.setFileMockType( imageType );
FileReader.setReadResult( 'load' );

dropCount = 0;
var assert = this.assert;

bender.tools.setHtmlWithSelection( this.editor, '<p class="p">Paste image here:^</p>' );
assertDropImage( {
editor: this.editor,
Expand All @@ -73,6 +107,9 @@
dropRange: {
dropContainer: this.editor.editable().findOne( '.p' ).getChild( 0 ),
dropOffset: 17
},
callback: function() {
assert(dropCount === 1, "custom image handler plugin did not receive file");
}
} );
},
Expand Down

0 comments on commit 607fa61

Please sign in to comment.