8
0

cloudservices.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 its properties 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 not throw an error when no config is provided', () => {
  40. return ClassicTestEditor
  41. .create( element, {
  42. plugins: [ CloudServices ]
  43. } );
  44. } );
  45. it( 'should provide token if tokenUrl is provided', () => {
  46. CloudServices.Token.initialToken = 'initial-token';
  47. return ClassicTestEditor
  48. .create( element, {
  49. plugins: [ CloudServices ],
  50. cloudServices: {
  51. tokenUrl: 'http://token-endpoint',
  52. }
  53. } )
  54. .then( editor => {
  55. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  56. expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
  57. return editor.destroy();
  58. } );
  59. } );
  60. it( 'should not provide token if tokenUrl is not provided', () => {
  61. CloudServices.Token.initialToken = 'initial-token';
  62. return ClassicTestEditor
  63. .create( element, {
  64. plugins: [ CloudServices ],
  65. cloudServices: {}
  66. } )
  67. .then( editor => {
  68. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  69. expect( cloudServicesPlugin.token ).to.equal( null );
  70. } );
  71. } );
  72. } );
  73. } );