cloudservices.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. return editor.destroy();
  48. } );
  49. } );
  50. it( 'should not throw an error when no config is provided', () => {
  51. return ClassicTestEditor
  52. .create( element, {
  53. plugins: [ CloudServices ]
  54. } )
  55. .then( editor => {
  56. return editor.destroy();
  57. } );
  58. } );
  59. it( 'should not expose any default uploadUrl', () => {
  60. return ClassicTestEditor
  61. .create( element, {
  62. plugins: [ CloudServices ]
  63. } )
  64. .then( editor => {
  65. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  66. expect( cloudServicesPlugin.uploadUrl ).to.be.undefined;
  67. return editor.destroy();
  68. } );
  69. } );
  70. it( 'should use provided uploadUrl', () => {
  71. return ClassicTestEditor
  72. .create( element, {
  73. plugins: [ CloudServices ],
  74. cloudServices: {
  75. uploadUrl: 'https://some-upload-url/'
  76. }
  77. } )
  78. .then( editor => {
  79. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  80. expect( cloudServicesPlugin.uploadUrl ).to.equal( 'https://some-upload-url/' );
  81. return editor.destroy();
  82. } );
  83. } );
  84. it( 'should provide token if tokenUrl is provided', () => {
  85. CloudServices.Token.initialToken = 'initial-token';
  86. return ClassicTestEditor
  87. .create( element, {
  88. plugins: [ CloudServices ],
  89. cloudServices: {
  90. tokenUrl: 'http://token-endpoint',
  91. }
  92. } )
  93. .then( editor => {
  94. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  95. expect( cloudServicesPlugin.token.value ).to.equal( 'initial-token' );
  96. return editor.destroy();
  97. } );
  98. } );
  99. it( 'should not provide token if tokenUrl is not provided', () => {
  100. CloudServices.Token.initialToken = 'initial-token';
  101. return ClassicTestEditor
  102. .create( element, {
  103. plugins: [ CloudServices ],
  104. cloudServices: {}
  105. } )
  106. .then( editor => {
  107. const cloudServicesPlugin = editor.plugins.get( CloudServices );
  108. expect( cloudServicesPlugin.token ).to.equal( null );
  109. return editor.destroy();
  110. } );
  111. } );
  112. } );
  113. } );