cloudservices.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  10. const Token = CloudServices.Token;
  11. describe( 'CloudServices', () => {
  12. let element;
  13. beforeEach( () => {
  14. CloudServices.Token = TokenMock;
  15. element = document.createElement( 'div' );
  16. document.body.appendChild( element );
  17. } );
  18. afterEach( () => {
  19. CloudServices.Token = Token;
  20. document.body.removeChild( element );
  21. } );
  22. describe( 'init()', () => {
  23. it( 'should expose option property based on config', () => {
  24. return ClassicTestEditor
  25. .create( element, {
  26. plugins: [ CloudServices ],
  27. cloudServices: {
  28. tokenUrl: 'http://token-endpoint',
  29. additionalOption: 'some-value'
  30. }
  31. } )
  32. .then( editor => {
  33. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  34. expect( cloudServicesPlugin ).to.be.instanceOf( CloudServices );
  35. expect( cloudServicesPlugin.tokenUrl ).to.equal( 'http://token-endpoint' );
  36. expect( cloudServicesPlugin.additionalOption ).to.equal( 'some-value' );
  37. return editor.destroy();
  38. } );
  39. } );
  40. it( 'should provide token', () => {
  41. CloudServices.Token.initialToken = 'initial-token';
  42. return ClassicTestEditor
  43. .create( element, {
  44. plugins: [ CloudServices ],
  45. cloudServices: {
  46. tokenUrl: 'http://token-endpoint',
  47. }
  48. } )
  49. .then( editor => {
  50. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  51. expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
  52. return editor.destroy();
  53. } );
  54. } );
  55. it( 'should throw an error when token URL is not provided', done => {
  56. CloudServices.Token.initialToken = 'initial-token';
  57. ClassicTestEditor
  58. .create( element, {
  59. plugins: [ CloudServices ],
  60. cloudServices: {}
  61. } )
  62. .catch( err => {
  63. expect( err.name ).to.equal( 'CKEditorError' );
  64. expect( err.message, '12' ).to.match( /cloudservices-token-endpoint-not-provided/ );
  65. done();
  66. } );
  67. } );
  68. } );
  69. } );