8
0
Quellcode durchsuchen

Internal: Added default config.cloudServices.uploadUrl setting. Closes #1.

Piotrek Koszuliński vor 8 Jahren
Ursprung
Commit
b000406ccc

+ 2 - 0
packages/ckeditor5-easy-image/src/cloudservicesuploadadapter.js

@@ -36,6 +36,8 @@ export default class CloudServicesUploadAdapter extends Plugin {
 		const editor = this.editor;
 		const config = editor.config;
 
+		config.define( 'cloudServices.uploadUrl', 'https://files.cke-cs.com/upload/' );
+
 		const token = config.get( 'cloudServices.token' );
 		const uploadUrl = config.get( 'cloudServices.uploadUrl' );
 

+ 46 - 19
packages/ckeditor5-easy-image/tests/cloudservicesuploadadapter.js

@@ -36,31 +36,58 @@ describe( 'CloudServicesUploadAdapter', () => {
 		window.document.body.removeChild( div );
 	} );
 
-	describe( 'init', () => {
+	describe( 'init()', () => {
 		it( 'should set loader', () => {
 			UploadGatewayMock.lastToken = undefined;
 
-			return ClassicTestEditor.create( div, {
-				plugins: [ CloudServicesUploadAdapter ],
-				cloudServices: {
-					documentId: 'app',
-					token: 'abc',
-					uploadUrl: 'http://upload.mock.url/'
-				}
-			} ).then( () => {
-				expect( UploadGatewayMock.lastToken ).to.equal( 'abc' );
-				expect( UploadGatewayMock.lastUploadUrl ).to.equal( 'http://upload.mock.url/' );
-			} );
+			return ClassicTestEditor
+				.create( div, {
+					plugins: [ CloudServicesUploadAdapter ],
+					cloudServices: {
+						token: 'abc',
+						uploadUrl: 'http://upload.mock.url/'
+					}
+				} )
+				.then( editor => {
+					expect( UploadGatewayMock.lastToken ).to.equal( 'abc' );
+					expect( UploadGatewayMock.lastUploadUrl ).to.equal( 'http://upload.mock.url/' );
+
+					return editor.destroy();
+				} );
 		} );
 
 		it( 'should not set loader if there is no token', () => {
 			UploadGatewayMock.lastToken = undefined;
 
-			return ClassicTestEditor.create( div, {
-				plugins: [ CloudServicesUploadAdapter ]
-			} ).then( () => {
-				expect( UploadGatewayMock.lastToken ).to.be.an( 'undefined' );
-			} );
+			return ClassicTestEditor
+				.create( div, {
+					plugins: [ CloudServicesUploadAdapter ]
+				} )
+				.then( editor => {
+					expect( UploadGatewayMock.lastToken ).to.be.an( 'undefined' );
+
+					return editor.destroy();
+				} );
+		} );
+
+		it( 'should set the default config.cloudServices.uploadUrl', () => {
+			const expectedDefaultUrl = 'https://files.cke-cs.com/upload/';
+
+			return ClassicTestEditor
+				.create( div, {
+					plugins: [ CloudServicesUploadAdapter ],
+					cloudServices: {
+						token: 'abc'
+					}
+				} )
+				.then( editor => {
+					expect( UploadGatewayMock.lastToken ).to.equal( 'abc' );
+					expect( UploadGatewayMock.lastUploadUrl ).to.equal( expectedDefaultUrl );
+
+					expect( editor.config.get( 'cloudServices.uploadUrl' ) ).to.equal( expectedDefaultUrl );
+
+					return editor.destroy();
+				} );
 		} );
 	} );
 
@@ -85,7 +112,7 @@ describe( 'CloudServicesUploadAdapter', () => {
 			return editor.destroy();
 		} );
 
-		describe( 'upload', () => {
+		describe( 'upload()', () => {
 			it( 'should mock upload', done => {
 				const loader = fileRepository.createLoader( createNativeFileMock() );
 
@@ -113,7 +140,7 @@ describe( 'CloudServicesUploadAdapter', () => {
 			} );
 		} );
 
-		describe( 'abort', () => {
+		describe( 'abort()', () => {
 			it( 'should call abort on the CSS uploader', () => {
 				const loader = fileRepository.createLoader( createNativeFileMock() );
 

+ 43 - 36
packages/ckeditor5-easy-image/tests/easyimage.js

@@ -27,14 +27,18 @@ describe( 'EasyImage', () => {
 		const div = window.document.createElement( 'div' );
 		window.document.body.appendChild( div );
 
-		return ClassicTestEditor.create( div, {
-			plugins: [ EasyImage ]
-		} ).then( editor => {
-			const easyImage = editor.plugins.get( EasyImage );
-			expect( easyImage ).to.be.an.instanceOf( EasyImage );
+		return ClassicTestEditor
+			.create( div, {
+				plugins: [ EasyImage ]
+			} )
+			.then( editor => {
+				const easyImage = editor.plugins.get( EasyImage );
+				expect( easyImage ).to.be.an.instanceOf( EasyImage );
 
-			window.document.body.removeChild( div );
-		} );
+				window.document.body.removeChild( div );
+
+				return editor.destroy();
+			} );
 	} );
 
 	describe( 'integration tests', () => {
@@ -52,6 +56,7 @@ describe( 'EasyImage', () => {
 						reader.onload();
 					}
 				};
+
 				return reader;
 			} );
 		} );
@@ -72,37 +77,39 @@ describe( 'EasyImage', () => {
 		} );
 
 		it( 'should enable easy image uploading', () => {
-			return ClassicTestEditor.create( div, {
-				plugins: [
-					Paragraph, EasyImage
-				],
-				cloudServices: {
-					token: 'abc',
-					uploadUrl: 'http://upload.mock.url/'
-				}
-			} ).then( editor => {
-				const notification = editor.plugins.get( 'Notification' );
-				const upload = editor.plugins.get( CloudServicesUploadAdapter );
-
-				return new Promise( ( resolve, reject ) => {
-					notification.on( 'show:warning', ( evt, data ) => {
-						reject( new Error( data.title ) );
-					} );
-
-					editor.document.on( 'change', () => {
-						// Check whether the image is uploaded and the image's src is replaced correctly.
-						if ( editor.getData() === '<figure class="image"><img src="http://image.mock.url/"></figure>' ) {
-							resolve();
-						}
-					} );
-
-					editor.execute( 'imageUpload', { file: createNativeFileMock() } );
-
-					setTimeout( () => {
-						upload._uploadGateway.resolveLastUpload();
+			return ClassicTestEditor
+				.create( div, {
+					plugins: [
+						Paragraph, EasyImage
+					],
+					cloudServices: {
+						token: 'abc',
+						uploadUrl: 'http://upload.mock.url/'
+					}
+				} )
+				.then( editor => {
+					const notification = editor.plugins.get( 'Notification' );
+					const upload = editor.plugins.get( CloudServicesUploadAdapter );
+
+					return new Promise( ( resolve, reject ) => {
+						notification.on( 'show:warning', ( evt, data ) => {
+							reject( new Error( data.title ) );
+						} );
+
+						editor.document.on( 'change', () => {
+							// Check whether the image is uploaded and the image's src is replaced correctly.
+							if ( editor.getData() === '<figure class="image"><img src="http://image.mock.url/"></figure>' ) {
+								editor.destroy().then( resolve );
+							}
+						} );
+
+						editor.execute( 'imageUpload', { file: createNativeFileMock() } );
+
+						setTimeout( () => {
+							upload._uploadGateway.resolveLastUpload();
+						} );
 					} );
 				} );
-			} );
 		} );
 	} );
 } );

+ 1 - 3
packages/ckeditor5-easy-image/tests/manual/easyimage.js

@@ -18,15 +18,13 @@ import uid from '@ckeditor/ckeditor5-utils/src/uid';
 // Images uploaded during the free trial will not be deleted for the whole trial period and additionally the trial service can be converted
 // into a subscription at any moment, allowing you to preserve all uploaded images.
 const CLOUD_SERVICE_TOKEN_URL = 'https://j2sns7jmy0.execute-api.eu-central-1.amazonaws.com/prod/token';
-const CLOUD_SERVICE_UPLOAD_URL = 'https://files.cke-cs.com/upload/';
 
 getToken( { id: uid() } )
 	.then( token => {
 		return ClassicEditor
 			.create( document.querySelector( '#editor' ), {
 				cloudServices: {
-					token,
-					uploadUrl: CLOUD_SERVICE_UPLOAD_URL
+					token
 				},
 				plugins: [ ArticlePluginSet, EasyImage ],
 				toolbar: [ 'headings', 'undo', 'redo', 'insertImage' ],