How to use the @ckeditor/ckeditor5-upload/tests/_utils/mocks.createNativeFileMock function in @ckeditor/ckeditor5-upload

To help you get started, we’ve selected a few @ckeditor/ckeditor5-upload examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ckeditor / ckeditor5-image / tests / imageupload / imageuploadprogress.js View on Github external
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 =&gt; {
			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>
github ckeditor / ckeditor5-image / tests / imageupload / imageuploadediting.js View on Github external
it( 'should create responsive image if server return multiple images', done =&gt; {
		const file = createNativeFileMock();
		setModelData( model, '{}foo bar' );
		editor.execute( 'imageUpload', { file } );

		model.document.once( 'change', () =&gt; {
			model.document.once( 'change', () =&gt; {
				tryExpect( done, () =&gt; {
					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( () =&gt; adapterMocks[ 0 ].mockSuccess( { default: 'image.png', 500: 'image-500.png', 800: 'image-800.png' } ) );
github ckeditor / ckeditor5-image / tests / imageupload / imageuploadcommand.js View on Github external
it( 'should use parent batch', () =&gt; {
			const file = createNativeFileMock();

			setModelData( model, '[]foo' );

			model.change( writer =&gt; {
				expect( writer.batch.operations ).to.length( 0 );

				command.execute( { file } );

				expect( writer.batch.operations ).to.length.above( 0 );
			} );
		} );
github ckeditor / ckeditor5-image / tests / imageupload / imageuploadediting.js View on Github external
it( 'should insert image when is pasted on allowed position when ImageUploadCommand is disabled', () =&gt; {
		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>`
		);
	} );
github ckeditor / ckeditor5-image / tests / imageupload / imageuploadediting.js View on Github external
it( 'should not insert image nor crash when pasted image could not be inserted', () =&gt; {
		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( '[]' );
	} );
github ckeditor / ckeditor5-image / tests / imageupload / imageuploadprogress.js View on Github external
it( 'should convert image\'s "reading" uploadStatus attribute', () =&gt; {
		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>'
		);
	} );
github ckeditor / ckeditor5-image / tests / imageupload / imageuploadui.js View on Github external
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 ] ] );
	} );
} );
github ckeditor / ckeditor5-image / tests / imageupload / imageuploadcommand.js View on Github external
it( 'should insert image at selection position as other widgets', () =&gt; {
			const file = createNativeFileMock();
			setModelData( model, 'f[o]o' );

			command.execute( { file } );

			const id = fileRepository.getLoader( file ).id;
			expect( getModelData( model ) )
				.to.equal( `[<img>]foo` );
		} );