Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #23 from ckeditor/context
Browse files Browse the repository at this point in the history
Other: Changed the `CloudServices` plugin to a context plugin. Part of ckeditor/ckeditor5#5891.
  • Loading branch information
Reinmar authored Jan 29, 2020
2 parents b98b457 + 854ffbd commit 12ca96d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 47 deletions.
7 changes: 3 additions & 4 deletions src/cloudservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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
*/
Expand All @@ -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' ) || {};

Expand Down
86 changes: 43 additions & 43 deletions tests/cloudservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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' );
Expand All @@ -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();
} );
} );
} );
} );

0 comments on commit 12ca96d

Please sign in to comment.