| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* global document */
- import CloudServices from '../src/cloudservices';
- import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
- import TokenMock from './_utils/tokenmock';
- const Token = CloudServices.Token;
- describe( 'CloudServices', () => {
- let element;
- beforeEach( () => {
- CloudServices.Token = TokenMock;
- element = document.createElement( 'div' );
- document.body.appendChild( element );
- } );
- afterEach( () => {
- CloudServices.Token = Token;
- document.body.removeChild( element );
- } );
- describe( 'init()', () => {
- it( 'should expose its properties based on config', () => {
- return ClassicTestEditor
- .create( element, {
- plugins: [ CloudServices ],
- cloudServices: {
- tokenUrl: 'http://token-endpoint',
- additionalOption: 'some-value'
- }
- } )
- .then( editor => {
- const cloudServicesPlugin = editor.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();
- } );
- } );
- it( 'should not throw an error when no config is provided', () => {
- return ClassicTestEditor
- .create( element, {
- plugins: [ CloudServices ]
- } );
- } );
- it( 'should expose default uploadUrl if is not provided', () => {
- return ClassicTestEditor
- .create( element, {
- plugins: [ CloudServices ]
- } )
- .then( editor => {
- const cloudServicesPlugin = editor.plugins.get( CloudServices );
- expect( cloudServicesPlugin.uploadUrl ).to.equal( 'https://files.cke-cs.com/upload/' );
- } );
- } );
- it( 'should use provided uploadUrl', () => {
- return ClassicTestEditor
- .create( element, {
- plugins: [ CloudServices ],
- cloudServices: {
- uploadUrl: 'https://some-upload-url/'
- }
- } )
- .then( editor => {
- const cloudServicesPlugin = editor.plugins.get( CloudServices );
- expect( cloudServicesPlugin.uploadUrl ).to.equal( 'https://some-upload-url/' );
- } );
- } );
- it( 'should provide token if tokenUrl is provided', () => {
- CloudServices.Token.initialToken = 'initial-token';
- return ClassicTestEditor
- .create( element, {
- plugins: [ CloudServices ],
- cloudServices: {
- tokenUrl: 'http://token-endpoint',
- }
- } )
- .then( editor => {
- const cloudServicesPlugin = editor.plugins.get( CloudServices );
- expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
- return editor.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 );
- expect( cloudServicesPlugin.token ).to.equal( null );
- } );
- } );
- } );
- } );
|