|
|
@@ -8,7 +8,7 @@
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
|
-
|
|
|
+import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
import ImageEditing from '@ckeditor/ckeditor5-image/src/image/imageediting';
|
|
|
import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
|
|
|
@@ -71,18 +71,46 @@ describe( 'CKFinderCommand', () => {
|
|
|
window.CKFinder = {
|
|
|
modal: config => {
|
|
|
config.onInit( finderMock );
|
|
|
+ },
|
|
|
+ popup: config => {
|
|
|
+ config.onInit( finderMock );
|
|
|
}
|
|
|
};
|
|
|
} );
|
|
|
|
|
|
it( 'should register proper listeners on CKFinder instance', () => {
|
|
|
-
|
|
|
command.execute();
|
|
|
|
|
|
expect( finderMock ).to.have.property( 'files:choose' );
|
|
|
expect( finderMock ).to.have.property( 'file:choose:resizedImage' );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should use "CKFinder.modal" as default CKFinder opener method', () => {
|
|
|
+ const spy = sinon.spy( window.CKFinder, 'modal' );
|
|
|
+
|
|
|
+ command.execute();
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should use "CKFinder.modal" as default CKFinder opener method', () => {
|
|
|
+ const spy = sinon.spy( window.CKFinder, 'popup' );
|
|
|
+
|
|
|
+ editor.config.set( 'ckfinder.openerMethod', 'popup' );
|
|
|
+
|
|
|
+ command.execute();
|
|
|
+
|
|
|
+ sinon.assert.calledOnce( spy );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should throw if unsupported CKFinder opener method was set', () => {
|
|
|
+ editor.config.set( 'ckfinder.openerMethod', 'foobar' );
|
|
|
+
|
|
|
+ expect( () => {
|
|
|
+ command.execute();
|
|
|
+ } ).to.throw( CKEditorError, /ckfinder-unknown-openerMethod/ );
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should insert single chosen image as image widget', () => {
|
|
|
const url = 'foo/bar.jpg';
|
|
|
|
|
|
@@ -94,6 +122,21 @@ describe( 'CKFinderCommand', () => {
|
|
|
.to.equal( `[<image src="${ url }"></image>]<paragraph>foo</paragraph>` );
|
|
|
} );
|
|
|
|
|
|
+ it( 'should pass CKFinder config options', () => {
|
|
|
+ const spy = sinon.spy( window.CKFinder, 'modal' );
|
|
|
+
|
|
|
+ const connectorPath = 'foo/bar.php';
|
|
|
+ editor.config.set( 'ckfinder.config', { connectorPath } );
|
|
|
+
|
|
|
+ command.execute();
|
|
|
+
|
|
|
+ const openerMethodOptions = spy.args[ 0 ][ 0 ];
|
|
|
+
|
|
|
+ expect( openerMethodOptions ).to.have.property( 'chooseFiles', true );
|
|
|
+ expect( openerMethodOptions ).to.have.property( 'onInit' );
|
|
|
+ expect( openerMethodOptions ).to.have.property( 'connectorPath', connectorPath );
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'should insert multiple chosen images as image widget', () => {
|
|
|
const url1 = 'foo/bar1.jpg';
|
|
|
const url2 = 'foo/bar2.jpg';
|
|
|
@@ -123,7 +166,6 @@ describe( 'CKFinderCommand', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should use CKFinder Proxy for privately hosted files', () => {
|
|
|
-
|
|
|
const proxyUrl = 'bar/foo.jpg';
|
|
|
|
|
|
finderMock.request = () => proxyUrl;
|