| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- /* globals document */
- import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
- import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
- import Image from '../../src/image';
- import ImageUploadUI from '../../src/imageupload/imageuploadui';
- import ImageUploadEditing from '../../src/imageupload/imageuploadediting';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import Link from '@ckeditor/ckeditor5-link/src/link';
- import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder';
- import { createImageTypeRegExp, prepareIntegrations, createLabeledInputView } from '../../src/imageupload/utils';
- describe( 'Upload utils', () => {
- describe( 'createImageTypeRegExp()', () => {
- it( 'should return RegExp for testing regular mime type', () => {
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'image/png' ) ).to.be.true;
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'foo/png' ) ).to.be.false;
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'png' ) ).to.be.false;
- } );
- it( 'should return RegExp for testing mime type with dot', () => {
- expect( createImageTypeRegExp( [ 'vnd.microsoft.icon' ] ).test( 'image/vnd.microsoft.icon' ) ).to.be.true;
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'foo/vnd.microsoft.icon' ) ).to.be.false;
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'vnd.microsoft.icon' ) ).to.be.false;
- } );
- it( 'should return RegExp for testing mime type with dash', () => {
- expect( createImageTypeRegExp( [ 'x-xbitmap' ] ).test( 'image/x-xbitmap' ) ).to.be.true;
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'foo/x-xbitmap' ) ).to.be.false;
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'x-xbitmap' ) ).to.be.false;
- } );
- it( 'should return RegExp for testing mime type with plus', () => {
- expect( createImageTypeRegExp( [ 'svg+xml' ] ).test( 'image/svg+xml' ) ).to.be.true;
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'foo/svg+xml' ) ).to.be.false;
- expect( createImageTypeRegExp( [ 'png' ] ).test( 'svg+xml' ) ).to.be.false;
- } );
- } );
- describe( 'prepareIntegrations()', () => {
- it( 'should return "insetImageViaUrl" and "openCKFinder" integrations', async () => {
- const editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
- const editor = await ClassicEditor
- .create( editorElement, {
- plugins: [
- CKFinder,
- Paragraph,
- Image,
- ImageUploadEditing,
- ImageUploadUI
- ],
- image: {
- upload: {
- panel: {
- items: [
- 'insertImageViaUrl',
- 'openCKFinder'
- ]
- }
- }
- }
- } );
- const openCKFinderExtendedView = Object.values( prepareIntegrations( editor ) )[ 1 ];
- expect( openCKFinderExtendedView.class ).contains( 'ck-image-upload__ck-finder-button' );
- expect( openCKFinderExtendedView.label ).to.equal( 'Insert image or file' );
- expect( openCKFinderExtendedView.withText ).to.be.true;
- editor.destroy();
- editorElement.remove();
- } );
- it( 'should return only "insertImageViaUrl" integration and throw warning' +
- 'for "image-upload-integrations-invalid-view" error', async () => {
- const editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
- const editor = await ClassicEditor
- .create( editorElement, {
- plugins: [
- Paragraph,
- Image,
- ImageUploadEditing,
- ImageUploadUI
- ],
- image: {
- upload: {
- panel: {
- items: [
- 'insertImageViaUrl',
- 'openCKFinder'
- ]
- }
- }
- }
- } );
- expect( Object.values( prepareIntegrations( editor ) ).length ).to.equal( 1 );
- editor.destroy();
- editorElement.remove();
- } );
- it( 'should return only "link" integration', async () => {
- const editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
- const editor = await ClassicEditor
- .create( editorElement, {
- plugins: [
- Paragraph,
- Link,
- Image,
- ImageUploadEditing,
- ImageUploadUI
- ],
- image: {
- upload: {
- panel: {
- items: [
- 'link'
- ]
- }
- }
- }
- } );
- expect( Object.values( prepareIntegrations( editor ) ).length ).to.equal( 1 );
- expect( Object.values( prepareIntegrations( editor ) )[ 0 ].label ).to.equal( 'Link' );
- expect( Object.values( prepareIntegrations( editor ) )[ 0 ] ).to.be.instanceOf( ButtonView );
- editor.destroy();
- editorElement.remove();
- } );
- it( 'should return "insertImageViaUrl" integration, when no integrations were configured', async () => {
- const editorElement = document.createElement( 'div' );
- document.body.appendChild( editorElement );
- const editor = await ClassicEditor
- .create( editorElement, {
- plugins: [
- Paragraph,
- Image,
- ImageUploadEditing,
- ImageUploadUI
- ]
- } );
- expect( Object.keys( prepareIntegrations( editor ) ).length ).to.equal( 1 );
- editor.destroy();
- editorElement.remove();
- } );
- } );
- describe( 'createLabeledInputView()', () => {
- describe( 'image URL input view', () => {
- it( 'should have placeholder', () => {
- const view = createLabeledInputView( { t: val => val } );
- expect( view.fieldView.placeholder ).to.equal( 'https://example.com/src/image.png' );
- } );
- it( 'should have info text', () => {
- const view = createLabeledInputView( { t: val => val } );
- expect( view.infoText ).to.match( /^Paste the image source URL/ );
- } );
- } );
- } );
- } );
|