Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for failing test tests/plugins/easyimage/pasteintegration #3870

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions tests/plugins/easyimage/pasteintegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,37 @@
bender.editor = true;

function assertEasyImageUpcast( config ) {
var editor = config.editor,
var bot = config.bot,
editor = bot.editor,
pastedData = config.pastedData,
shouldUpcast = config.shouldUpcast,
// spy checks if paste listener in easyimage plugin activates an early return,
// by spying the method available after the early return statement.
upcastSpy = sinon.spy( editor.widgets.registered.easyimage, '_spawnLoader' );

bender.tools.range.setWithHtml( editor.editable(), '<p>[]</p>' );
bot.setData( '', function() {
bender.tools.range.setWithHtml( editor.editable(), '<p>[]</p>' );

bender.tools.emulatePaste( editor, pastedData );
bender.tools.emulatePaste( editor, pastedData );

editor.once( 'afterPaste', function() {
resume( function() {
upcastSpy.restore();
editor.once( 'afterPaste', function() {
resume( function() {
upcastSpy.restore();

if ( shouldUpcast ) {
sinon.assert.calledOnce( upcastSpy );
if ( shouldUpcast ) {
sinon.assert.calledOnce( upcastSpy );

assert.areNotSame( -1, editor.getData().indexOf( 'easyimage' ), 'there should be the image upcasted to the easyimage widget' );
} else {
sinon.assert.notCalled( upcastSpy );
assert.areNotSame( -1, editor.getData().indexOf( 'easyimage' ), 'there should be the image upcasted to the easyimage widget' );
} else {
sinon.assert.notCalled( upcastSpy );

assert.areSame( -1, editor.getData().indexOf( 'easyimage' ), 'there should not be an image upcasted to the easyimage widget' );
}
assert.areSame( -1, editor.getData().indexOf( 'easyimage' ), 'there should not be an image upcasted to the easyimage widget' );
}
} );
} );
} );

wait();
wait();
} );
}

bender.test( {
Expand All @@ -54,55 +57,55 @@

'test easyimage upcasts image/jpeg': function() {
assertEasyImageUpcast( {
editor: this.editor,
bot: this.editorBot,
pastedData: IMG.JPEG,
shouldUpcast: true
} );
},

'test easyimage upcasts image/gif': function() {
assertEasyImageUpcast( {
editor: this.editor,
bot: this.editorBot,
pastedData: IMG.GIF,
shouldUpcast: true
} );
},

'test easyimage upcasts image/png': function() {
assertEasyImageUpcast( {
editor: this.editor,
bot: this.editorBot,
pastedData: IMG.PNG,
shouldUpcast: true
} );
},

'test easyimage upcasts image/bmp': function() {
assertEasyImageUpcast( {
editor: this.editor,
bot: this.editorBot,
pastedData: IMG.BMP,
shouldUpcast: true
} );
},

'test easyimage not upcasts image/svg': function() {
assertEasyImageUpcast( {
editor: this.editor,
bot: this.editorBot,
pastedData: IMG.SVG,
shouldUpcast: false
} );
},

'test easyimage not upcasts image/foobar': function() {
assertEasyImageUpcast( {
editor: this.editor,
bot: this.editorBot,
pastedData: IMG.FAKE_IMAGE,
shouldUpcast: false
} );
},

'test easyimage not upcasts text/html': function() {
assertEasyImageUpcast( {
editor: this.editor,
bot: this.editorBot,
pastedData: IMG.HTML,
shouldUpcast: false
} );
Expand Down