utils.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  8. import Image from '../../src/image';
  9. import ImageUploadUI from '../../src/imageinsert/imageinsertui';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import Link from '@ckeditor/ckeditor5-link/src/link';
  12. import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder';
  13. import { prepareIntegrations, createLabeledInputView } from '../../src/imageinsert/utils';
  14. describe( 'Upload utils', () => {
  15. describe( 'prepareIntegrations()', () => {
  16. it( 'should return "insetImageViaUrl" and "openCKFinder" integrations', async () => {
  17. const editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. const editor = await ClassicEditor
  20. .create( editorElement, {
  21. plugins: [
  22. CKFinder,
  23. Paragraph,
  24. Image,
  25. ImageUploadUI
  26. ],
  27. image: {
  28. upload: {
  29. panel: {
  30. items: [
  31. 'insertImageViaUrl',
  32. 'openCKFinder'
  33. ]
  34. }
  35. }
  36. }
  37. } );
  38. const openCKFinderExtendedView = Object.values( prepareIntegrations( editor ) )[ 1 ];
  39. expect( openCKFinderExtendedView.class ).contains( 'ck-image-upload__ck-finder-button' );
  40. expect( openCKFinderExtendedView.label ).to.equal( 'Insert image or file' );
  41. expect( openCKFinderExtendedView.withText ).to.be.true;
  42. editor.destroy();
  43. editorElement.remove();
  44. } );
  45. it( 'should return only "insertImageViaUrl" integration and throw warning ' +
  46. 'for "image-upload-integrations-invalid-view" error', async () => {
  47. const editorElement = document.createElement( 'div' );
  48. document.body.appendChild( editorElement );
  49. const editor = await ClassicEditor
  50. .create( editorElement, {
  51. plugins: [
  52. Paragraph,
  53. Image,
  54. ImageUploadUI
  55. ],
  56. image: {
  57. upload: {
  58. panel: {
  59. items: [
  60. 'insertImageViaUrl',
  61. 'openCKFinder'
  62. ]
  63. }
  64. }
  65. }
  66. } );
  67. expect( Object.values( prepareIntegrations( editor ) ).length ).to.equal( 1 );
  68. editor.destroy();
  69. editorElement.remove();
  70. } );
  71. it( 'should return only "link" integration', async () => {
  72. const editorElement = document.createElement( 'div' );
  73. document.body.appendChild( editorElement );
  74. const editor = await ClassicEditor
  75. .create( editorElement, {
  76. plugins: [
  77. Paragraph,
  78. Link,
  79. Image,
  80. ImageUploadUI
  81. ],
  82. image: {
  83. upload: {
  84. panel: {
  85. items: [
  86. 'link'
  87. ]
  88. }
  89. }
  90. }
  91. } );
  92. expect( Object.values( prepareIntegrations( editor ) ).length ).to.equal( 1 );
  93. expect( Object.values( prepareIntegrations( editor ) )[ 0 ].label ).to.equal( 'Link' );
  94. expect( Object.values( prepareIntegrations( editor ) )[ 0 ] ).to.be.instanceOf( ButtonView );
  95. editor.destroy();
  96. editorElement.remove();
  97. } );
  98. it( 'should return "insertImageViaUrl" integration, when no integrations were configured', async () => {
  99. const editorElement = document.createElement( 'div' );
  100. document.body.appendChild( editorElement );
  101. const editor = await ClassicEditor
  102. .create( editorElement, {
  103. plugins: [
  104. Paragraph,
  105. Image,
  106. ImageUploadUI
  107. ]
  108. } );
  109. expect( Object.keys( prepareIntegrations( editor ) ).length ).to.equal( 1 );
  110. editor.destroy();
  111. editorElement.remove();
  112. } );
  113. } );
  114. describe( 'createLabeledInputView()', () => {
  115. describe( 'image URL input view', () => {
  116. it( 'should have placeholder', () => {
  117. const view = createLabeledInputView( { t: val => val } );
  118. expect( view.fieldView.placeholder ).to.equal( 'https://example.com/src/image.png' );
  119. } );
  120. it( 'should have info text', () => {
  121. const view = createLabeledInputView( { t: val => val } );
  122. expect( view.infoText ).to.match( /^Paste the image source URL/ );
  123. } );
  124. } );
  125. } );
  126. } );