cloudservices.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 expose default uploadUrl if is not provided', () => {
  46. return ClassicTestEditor
  47. .create( element, {
  48. plugins: [ CloudServices ]
  49. } )
  50. .then( editor => {
  51. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  52. expect( cloudServicesPlugin.uploadUrl ).to.equal( 'https://files.cke-cs.com/upload/' );
  53. } );
  54. } );
  55. it( 'should use provided uploadUrl', () => {
  56. return ClassicTestEditor
  57. .create( element, {
  58. plugins: [ CloudServices ],
  59. cloudServices: {
  60. uploadUrl: 'https://some-upload-url/'
  61. }
  62. } )
  63. .then( editor => {
  64. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  65. expect( cloudServicesPlugin.uploadUrl ).to.equal( 'https://some-upload-url/' );
  66. } );
  67. } );
  68. it( 'should provide token if tokenUrl is provided', () => {
  69. CloudServices.Token.initialToken = 'initial-token';
  70. return ClassicTestEditor
  71. .create( element, {
  72. plugins: [ CloudServices ],
  73. cloudServices: {
  74. tokenUrl: 'http://token-endpoint',
  75. }
  76. } )
  77. .then( editor => {
  78. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  79. expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
  80. return editor.destroy();
  81. } );
  82. } );
  83. it( 'should not provide token if tokenUrl is not provided', () => {
  84. CloudServices.Token.initialToken = 'initial-token';
  85. return ClassicTestEditor
  86. .create( element, {
  87. plugins: [ CloudServices ],
  88. cloudServices: {}
  89. } )
  90. .then( editor => {
  91. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  92. expect( cloudServicesPlugin.token ).to.equal( null );
  93. } );
  94. } );
  95. } );
  96. } );