Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it( 'should work correctly when there is no "reading" status and go straight to "uploading"', () => {
const fileRepository = editor.plugins.get( FileRepository );
const file = createNativeFileMock();
const loader = fileRepository.createLoader( file );
setModelData( model, '<img>' );
const image = doc.getRoot().getChild( 0 );
// Set attributes directly on image to simulate instant "uploading" status.
model.change( writer => {
writer.setAttribute( 'uploadStatus', 'uploading', image );
writer.setAttribute( 'uploadId', loader.id, image );
writer.setAttribute( 'src', 'image.png', image );
} );
expect( getViewData( view ) ).to.equal(
'[<figure class="ck-appear ck-widget image">' +
'<img src="image.png">' +
'<div class="ck-progress-bar"></div>' +</figure>
it( 'should create responsive image if server return multiple images', done => {
const file = createNativeFileMock();
setModelData( model, '{}foo bar' );
editor.execute( 'imageUpload', { file } );
model.document.once( 'change', () => {
model.document.once( 'change', () => {
tryExpect( done, () => {
expect( getViewData( view ) ).to.equal(
'[<figure class="ck-widget image">' +
'<img width="800" srcset="image-500.png 500w, image-800.png 800w" src="image.png" sizes="100vw">' +
'</figure>]<p>foo bar</p>'
);
expect( loader.status ).to.equal( 'idle' );
} );
}, { priority: 'lowest' } );
loader.file.then( () => adapterMocks[ 0 ].mockSuccess( { default: 'image.png', 500: 'image-500.png', 800: 'image-800.png' } ) );
it( 'should use parent batch', () => {
const file = createNativeFileMock();
setModelData( model, '[]foo' );
model.change( writer => {
expect( writer.batch.operations ).to.length( 0 );
command.execute( { file } );
expect( writer.batch.operations ).to.length.above( 0 );
} );
} );
it( 'should insert image when is pasted on allowed position when ImageUploadCommand is disabled', () => {
setModelData( model, 'foo[<img>]' );
const fileMock = createNativeFileMock();
const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
const command = editor.commands.get( 'imageUpload' );
expect( command.isEnabled ).to.be.false;
const targetRange = model.createRange( model.createPositionAt( doc.getRoot(), 0 ), model.createPositionAt( doc.getRoot(), 0 ) );
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
const id = fileRepository.getLoader( fileMock ).id;
expect( getModelData( model ) ).to.equal(
`[<img>]foo<img>`
);
} );
it( 'should not insert image nor crash when pasted image could not be inserted', () => {
model.schema.register( 'other', {
allowIn: '$root',
isLimit: true
} );
model.schema.extend( '$text', { allowIn: 'other' } );
editor.conversion.elementToElement( { model: 'other', view: 'p' } );
setModelData( model, '[]' );
const fileMock = createNativeFileMock();
const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
const targetRange = doc.selection.getFirstRange();
const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
expect( getModelData( model ) ).to.equal( '[]' );
} );
it( 'should convert image\'s "reading" uploadStatus attribute', () => {
setModelData( model, '[]foo' );
editor.execute( 'imageUpload', { file: createNativeFileMock() } );
expect( getViewData( view ) ).to.equal(
'[<figure class="ck-appear ck-image-upload-placeholder ck-widget image">' +
`<img src="data:image/svg+xml;utf8,${ imagePlaceholder }">` +
'<div class="ck-upload-placeholder-loader"></div>' +
'</figure>]<p>foo</p>'
);
} );
it( 'should work even if the FileList does not support iterators', () => {
const executeStub = sinon.stub( editor, 'execute' );
const button = editor.ui.componentFactory.create( 'imageUpload' );
const files = {
0: createNativeFileMock(),
length: 1
};
button.fire( 'done', files );
sinon.assert.calledOnce( executeStub );
expect( executeStub.firstCall.args[ 0 ] ).to.equal( 'imageUpload' );
expect( executeStub.firstCall.args[ 1 ].file ).to.deep.equal( [ files[ 0 ] ] );
} );
} );
it( 'should insert image at selection position as other widgets', () => {
const file = createNativeFileMock();
setModelData( model, 'f[o]o' );
command.execute( { file } );
const id = fileRepository.getLoader( file ).id;
expect( getModelData( model ) )
.to.equal( `[<img>]foo` );
} );