Browse Source

Merge pull request #46 from ckeditor/t/45

Fix: Pass CKFinder instance to a user-defined onInit() function. Closes #45.
Piotrek Koszuliński 6 years ago
parent
commit
21f465ccf4

+ 1 - 1
packages/ckeditor5-ckfinder/src/ckfindercommand.js

@@ -73,7 +73,7 @@ export default class CKFinderCommand extends Command {
 		options.onInit = finder => {
 			// Call original options.onInit if it was defined by user.
 			if ( originalOnInit ) {
-				originalOnInit();
+				originalOnInit( finder );
 			}
 
 			finder.on( 'files:choose', evt => {

+ 11 - 1
packages/ckeditor5-ckfinder/tests/ckfindercommand.js

@@ -194,7 +194,7 @@ describe( 'CKFinderCommand', () => {
 			expect( openerMethodOptions ).to.have.property( 'connectorPath', connectorPath );
 		} );
 
-		it( 'should call user defined config.onInit() function', () => {
+		it( 'should call user-defined config.onInit() function', () => {
 			const spy = sinon.spy();
 
 			editor.config.set( 'ckfinder.options.onInit', spy );
@@ -204,6 +204,16 @@ describe( 'CKFinderCommand', () => {
 			sinon.assert.calledOnce( spy );
 		} );
 
+		it( 'should pass CKFinder instance to a user-defined config.onInit() function', () => {
+			const spy = sinon.spy();
+
+			editor.config.set( 'ckfinder.options.onInit', spy );
+
+			command.execute();
+
+			sinon.assert.calledWithExactly( spy, finderMock );
+		} );
+
 		it( 'should pass editor default language to the CKFinder instance', () => {
 			const spy = sinon.spy( window.CKFinder, 'modal' );
 			command.execute();