Bladeren bron

Merge pull request #23 from ckeditor/context

Other: Changed the `CloudServices` plugin to a context plugin. Part of ckeditor/ckeditor5#5891.
Piotrek Koszuliński 5 jaren geleden
bovenliggende
commit
63201dc33f

+ 3 - 4
packages/ckeditor5-cloud-services/src/cloudservices.js

@@ -7,7 +7,7 @@
  * @module cloud-services/cloudservices
  */
 
-import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
+import ContextPlugin from '@ckeditor/ckeditor5-core/src/contextplugin';
 import Token from '@ckeditor/ckeditor-cloud-services-core/src/token/token';
 
 /**
@@ -18,7 +18,7 @@ import Token from '@ckeditor/ckeditor-cloud-services-core/src/token/token';
  *
  * @extends module:core/plugin~Plugin
  */
-export default class CloudServices extends Plugin {
+export default class CloudServices extends ContextPlugin {
 	/**
 	 * @inheritdoc
 	 */
@@ -30,8 +30,7 @@ export default class CloudServices extends Plugin {
 	 * @inheritDoc
 	 */
 	init() {
-		const editor = this.editor;
-		const config = editor.config;
+		const config = this.context.config;
 
 		const options = config.get( 'cloudServices' ) || {};
 

+ 43 - 43
packages/ckeditor5-cloud-services/tests/cloudservices.js

@@ -6,6 +6,7 @@
 /* global document */
 
 import CloudServices from '../src/cloudservices';
+import Context from '@ckeditor/ckeditor5-core/src/context';
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import TokenMock from './_utils/tokenmock';
 
@@ -27,29 +28,33 @@ describe( 'CloudServices', () => {
 
 	describe( 'init()', () => {
 		it( 'should expose its properties based on config', () => {
-			return ClassicTestEditor
-				.create( element, {
+			return Context
+				.create( {
 					plugins: [ CloudServices ],
 					cloudServices: {
 						tokenUrl: 'http://token-endpoint',
 						additionalOption: 'some-value'
 					}
 				} )
-				.then( editor => {
-					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+				.then( context => {
+					const cloudServicesPlugin = context.plugins.get( CloudServices );
 
 					expect( cloudServicesPlugin ).to.be.instanceOf( CloudServices );
 					expect( cloudServicesPlugin.tokenUrl ).to.equal( 'http://token-endpoint' );
 					expect( cloudServicesPlugin.additionalOption ).to.equal( 'some-value' );
 
-					return editor.destroy();
+					return context.destroy();
 				} );
 		} );
 
-		it( 'should be able to get by its plugin name', () => {
+		it( 'should work as an editor plugin', () => {
 			return ClassicTestEditor
 				.create( element, {
-					plugins: [ CloudServices ]
+					plugins: [ CloudServices ],
+					cloudServices: {
+						tokenUrl: 'http://token-endpoint',
+						additionalOption: 'some-value'
+					}
 				} )
 				.then( editor => {
 					const cloudServicesPlugin = editor.plugins.get( 'CloudServices' );
@@ -59,81 +64,76 @@ describe( 'CloudServices', () => {
 				} );
 		} );
 
+		it( 'should be able to get by its plugin name', () => {
+			return Context.create( { plugins: [ CloudServices ] } ).then( context => {
+				const cloudServicesPlugin = context.plugins.get( 'CloudServices' );
+
+				expect( cloudServicesPlugin ).to.be.instanceOf( CloudServices );
+
+				return context.destroy();
+			} );
+		} );
+
 		it( 'should not throw an error when no config is provided', () => {
-			return ClassicTestEditor
-				.create( element, {
-					plugins: [ CloudServices ]
-				} )
-				.then( editor => {
-					return editor.destroy();
-				} );
+			return Context.create( { plugins: [ CloudServices ] } ).then( context => context.destroy() );
 		} );
 
 		it( 'should not expose any default uploadUrl', () => {
-			return ClassicTestEditor
-				.create( element, {
-					plugins: [ CloudServices ]
-				} )
-				.then( editor => {
-					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+			return Context.create( { plugins: [ CloudServices ] } ).then( context => {
+				const cloudServicesPlugin = context.plugins.get( CloudServices );
 
-					expect( cloudServicesPlugin.uploadUrl ).to.be.undefined;
+				expect( cloudServicesPlugin.uploadUrl ).to.be.undefined;
 
-					return editor.destroy();
-				} );
+				return context.destroy();
+			} );
 		} );
 
 		it( 'should use provided uploadUrl', () => {
-			return ClassicTestEditor
-				.create( element, {
+			return Context
+				.create( {
 					plugins: [ CloudServices ],
 					cloudServices: {
 						uploadUrl: 'https://some-upload-url/'
 					}
 				} )
-				.then( editor => {
-					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+				.then( context => {
+					const cloudServicesPlugin = context.plugins.get( CloudServices );
 
 					expect( cloudServicesPlugin.uploadUrl ).to.equal( 'https://some-upload-url/' );
 
-					return editor.destroy();
+					return context.destroy();
 				} );
 		} );
 
 		it( 'should provide token if tokenUrl is provided', () => {
 			CloudServices.Token.initialToken = 'initial-token';
 
-			return ClassicTestEditor
-				.create( element, {
+			return Context
+				.create( {
 					plugins: [ CloudServices ],
 					cloudServices: {
 						tokenUrl: 'http://token-endpoint',
 					}
 				} )
-				.then( editor => {
-					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+				.then( context => {
+					const cloudServicesPlugin = context.plugins.get( CloudServices );
 
 					expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
 
-					return editor.destroy();
+					return context.destroy();
 				} );
 		} );
 
 		it( 'should not provide token if tokenUrl is not provided', () => {
 			CloudServices.Token.initialToken = 'initial-token';
 
-			return ClassicTestEditor
-				.create( element, {
-					plugins: [ CloudServices ],
-					cloudServices: {}
-				} )
-				.then( editor => {
-					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+			return Context.create( { plugins: [ CloudServices ] } ).then( context => {
+				const cloudServicesPlugin = context.plugins.get( CloudServices );
 
-					expect( cloudServicesPlugin.token ).to.equal( null );
+				expect( cloudServicesPlugin.token ).to.equal( null );
 
-					return editor.destroy();
-				} );
+				return context.destroy();
+			} );
 		} );
 	} );
 } );