Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #285 from ckeditor/t/ckeditor5-upload/92
Browse files Browse the repository at this point in the history
Tests: Added assertion to the `ImageUploadEditing` tests to make sure the `clipboardInput` event is handled correctly. See ckeditor/ckeditor5-upload#92.
  • Loading branch information
Reinmar authored Mar 28, 2019
2 parents 7093dfa + f3468b6 commit 160c5db
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/imageupload/imageuploadediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ImageUploadCommand from '../../src/imageupload/imageuploadcommand';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
import DataTransfer from '@ckeditor/ckeditor5-clipboard/src/datatransfer';
import EventInfo from '@ckeditor/ckeditor5-utils/src/eventinfo';

import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
import { UploadAdapterMock, createNativeFileMock, NativeFileReaderMock } from '@ckeditor/ckeditor5-upload/tests/_utils/mocks';
Expand Down Expand Up @@ -112,12 +113,14 @@ describe( 'ImageUploadEditing', () => {
const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 1 ), model.createPositionAt( doc.getRoot(), 1 ) );
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
const eventInfo = new EventInfo( viewDocument, 'clipboardInput' );
viewDocument.fire( eventInfo, { dataTransfer, targetRanges: [ targetViewRange ] } );

const id = fileRepository.getLoader( fileMock ).id;
expect( getModelData( model ) ).to.equal(
`<paragraph>foo</paragraph>[<image uploadId="${ id }" uploadStatus="reading"></image>]`
);
expect( eventInfo.stop.called ).to.be.true;
} );

it( 'should insert image at optimized position when is pasted', () => {
Expand Down Expand Up @@ -219,9 +222,11 @@ describe( 'ImageUploadEditing', () => {
const targetRange = doc.selection.getFirstRange();
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );

viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
const eventInfo = new EventInfo( viewDocument, 'clipboardInput' );
viewDocument.fire( eventInfo, { dataTransfer, targetRanges: [ targetViewRange ] } );

expect( getModelData( model ) ).to.equal( '<paragraph>foo[]</paragraph>' );
expect( eventInfo.stop.called ).to.be.undefined;
} );

it( 'should not insert image when file is null', () => {
Expand Down

0 comments on commit 160c5db

Please sign in to comment.