8
0

cloudservices.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import CloudServices from '../src/cloudservices';
  7. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  8. import TokenMock from './_utils/tokenmock';
  9. const Token = CloudServices.Token;
  10. describe( 'CloudServices', () => {
  11. let element;
  12. beforeEach( () => {
  13. CloudServices.Token = TokenMock;
  14. element = document.createElement( 'div' );
  15. document.body.appendChild( element );
  16. } );
  17. afterEach( () => {
  18. CloudServices.Token = Token;
  19. document.body.removeChild( element );
  20. } );
  21. describe( 'init()', () => {
  22. it( 'should expose option property based on config', () => {
  23. return ClassicTestEditor
  24. .create( element, {
  25. plugins: [ CloudServices ],
  26. cloudServices: {
  27. tokenUrl: 'http://token-endpoint',
  28. additionalOption: 'some-value'
  29. }
  30. } )
  31. .then( editor => {
  32. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  33. expect( cloudServicesPlugin ).to.be.instanceOf( CloudServices );
  34. expect( cloudServicesPlugin.tokenUrl ).to.equal( 'http://token-endpoint' );
  35. expect( cloudServicesPlugin.additionalOption ).to.equal( 'some-value' );
  36. return editor.destroy();
  37. } );
  38. } );
  39. it( 'should provide token', () => {
  40. CloudServices.Token.initialToken = 'initial-token';
  41. return ClassicTestEditor
  42. .create( element, {
  43. plugins: [ CloudServices ],
  44. cloudServices: {
  45. tokenUrl: 'http://token-endpoint',
  46. }
  47. } )
  48. .then( editor => {
  49. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  50. expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
  51. return editor.destroy();
  52. } );
  53. } );
  54. it( 'should throw an error when token URL is not provided', done => {
  55. CloudServices.Token.initialToken = 'initial-token';
  56. ClassicTestEditor
  57. .create( element, {
  58. plugins: [ CloudServices ],
  59. cloudServices: {}
  60. } )
  61. .catch( err => {
  62. expect( err.name ).to.equal( 'CKEditorError' );
  63. expect( err.message, '12' ).to.match( /cloudservices-token-endpoint-not-provided/ );
  64. done();
  65. } );
  66. } );
  67. } );
  68. } );