utils.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. insert: {
  29. integrations: [
  30. 'insertImageViaUrl',
  31. 'openCKFinder'
  32. ]
  33. }
  34. }
  35. } );
  36. const openCKFinderExtendedView = Object.values( prepareIntegrations( editor ) )[ 1 ];
  37. expect( openCKFinderExtendedView.class ).contains( 'ck-image-insert__ck-finder-button' );
  38. expect( openCKFinderExtendedView.label ).to.equal( 'Insert image or file' );
  39. expect( openCKFinderExtendedView.withText ).to.be.true;
  40. editor.destroy();
  41. editorElement.remove();
  42. } );
  43. it( 'should return only "insertImageViaUrl" integration and throw warning ' +
  44. 'for "image-upload-integrations-invalid-view" error', async () => {
  45. const editorElement = document.createElement( 'div' );
  46. document.body.appendChild( editorElement );
  47. const editor = await ClassicEditor
  48. .create( editorElement, {
  49. plugins: [
  50. Paragraph,
  51. Image,
  52. ImageUploadUI
  53. ],
  54. image: {
  55. insert: {
  56. integrations: [
  57. 'insertImageViaUrl',
  58. 'openCKFinder'
  59. ]
  60. }
  61. }
  62. } );
  63. expect( Object.values( prepareIntegrations( editor ) ).length ).to.equal( 1 );
  64. editor.destroy();
  65. editorElement.remove();
  66. } );
  67. it( 'should return only "link" integration', async () => {
  68. const editorElement = document.createElement( 'div' );
  69. document.body.appendChild( editorElement );
  70. const editor = await ClassicEditor
  71. .create( editorElement, {
  72. plugins: [
  73. Paragraph,
  74. Link,
  75. Image,
  76. ImageUploadUI
  77. ],
  78. image: {
  79. insert: {
  80. integrations: [
  81. 'link'
  82. ]
  83. }
  84. }
  85. } );
  86. expect( Object.values( prepareIntegrations( editor ) ).length ).to.equal( 1 );
  87. expect( Object.values( prepareIntegrations( editor ) )[ 0 ].label ).to.equal( 'Link' );
  88. expect( Object.values( prepareIntegrations( editor ) )[ 0 ] ).to.be.instanceOf( ButtonView );
  89. editor.destroy();
  90. editorElement.remove();
  91. } );
  92. it( 'should return "insertImageViaUrl" integration, when no integrations were configured', async () => {
  93. const editorElement = document.createElement( 'div' );
  94. document.body.appendChild( editorElement );
  95. const editor = await ClassicEditor
  96. .create( editorElement, {
  97. plugins: [
  98. Paragraph,
  99. Image,
  100. ImageUploadUI
  101. ]
  102. } );
  103. expect( Object.keys( prepareIntegrations( editor ) ).length ).to.equal( 1 );
  104. editor.destroy();
  105. editorElement.remove();
  106. } );
  107. } );
  108. describe( 'createLabeledInputView()', () => {
  109. describe( 'image URL input view', () => {
  110. it( 'should have placeholder', () => {
  111. const view = createLabeledInputView( { t: val => val } );
  112. expect( view.fieldView.placeholder ).to.equal( 'https://example.com/src/image.png' );
  113. } );
  114. it( 'should have info text', () => {
  115. const view = createLabeledInputView( { t: val => val } );
  116. expect( view.infoText ).to.match( /^Paste the image source URL/ );
  117. } );
  118. } );
  119. } );
  120. } );