diff --git a/src/cloudservices.js b/src/cloudservices.js index c22ccb6..009deb4 100644 --- a/src/cloudservices.js +++ b/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' ) || {}; diff --git a/tests/cloudservices.js b/tests/cloudservices.js index 1a510ab..57469eb 100644 --- a/tests/cloudservices.js +++ b/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(); + } ); } ); } ); } );