cloudservices.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  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 be able to get by its plugin name', () => {
  40. return ClassicTestEditor
  41. .create( element, {
  42. plugins: [ CloudServices ]
  43. } )
  44. .then( editor => {
  45. const cloudServicesPlugin = editor.plugins.get( 'CloudServices' );
  46. expect( cloudServicesPlugin ).to.be.instanceOf( CloudServices );
  47. } );
  48. } );
  49. it( 'should not throw an error when no config is provided', () => {
  50. return ClassicTestEditor
  51. .create( element, {
  52. plugins: [ CloudServices ]
  53. } );
  54. } );
  55. it( 'should not expose any default uploadUrl', () => {
  56. return ClassicTestEditor
  57. .create( element, {
  58. plugins: [ CloudServices ]
  59. } )
  60. .then( editor => {
  61. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  62. expect( cloudServicesPlugin.uploadUrl ).to.be.undefined;
  63. } );
  64. } );
  65. it( 'should use provided uploadUrl', () => {
  66. return ClassicTestEditor
  67. .create( element, {
  68. plugins: [ CloudServices ],
  69. cloudServices: {
  70. uploadUrl: 'https://some-upload-url/'
  71. }
  72. } )
  73. .then( editor => {
  74. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  75. expect( cloudServicesPlugin.uploadUrl ).to.equal( 'https://some-upload-url/' );
  76. } );
  77. } );
  78. it( 'should provide token if tokenUrl is provided', () => {
  79. CloudServices.Token.initialToken = 'initial-token';
  80. return ClassicTestEditor
  81. .create( element, {
  82. plugins: [ CloudServices ],
  83. cloudServices: {
  84. tokenUrl: 'http://token-endpoint',
  85. }
  86. } )
  87. .then( editor => {
  88. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  89. expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
  90. return editor.destroy();
  91. } );
  92. } );
  93. it( 'should not provide token if tokenUrl is not provided', () => {
  94. CloudServices.Token.initialToken = 'initial-token';
  95. return ClassicTestEditor
  96. .create( element, {
  97. plugins: [ CloudServices ],
  98. cloudServices: {}
  99. } )
  100. .then( editor => {
  101. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  102. expect( cloudServicesPlugin.token ).to.equal( null );
  103. } );
  104. } );
  105. } );
  106. } );