瀏覽代碼

Aligned test with engine changes.

Oskar Wróbel 8 年之前
父節點
當前提交
2f9ad4e371

+ 1 - 1
packages/ckeditor5-upload/src/imageuploadcommand.js

@@ -37,7 +37,7 @@ export default class ImageUploadCommand extends Command {
 		const selection = doc.selection;
 		const fileRepository = editor.plugins.get( FileRepository );
 
-		editor.model.enqueueChange( () => {
+		editor.model.change( () => {
 			const loader = fileRepository.createLoader( file );
 
 			// Do not throw when upload adapter is not set. FileRepository will log an error anyway.

+ 6 - 6
packages/ckeditor5-upload/tests/imageuploadbutton.js

@@ -20,7 +20,7 @@ import { createNativeFileMock, AdapterMock } from './_utils/mocks';
 import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'ImageUploadButton', () => {
-	let editor, doc, editorElement, fileRepository;
+	let editor, model, editorElement, fileRepository;
 
 	class UploadAdapterPluginMock extends Plugin {
 		init() {
@@ -41,7 +41,7 @@ describe( 'ImageUploadButton', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-				doc = editor.document;
+				model = editor.model;
 
 				// Hide all notifications (prevent alert() calls).
 				const notification = editor.plugins.get( Notification );
@@ -93,13 +93,13 @@ describe( 'ImageUploadButton', () => {
 		const button = editor.ui.componentFactory.create( 'insertImage' );
 		const files = [ createNativeFileMock() ];
 
-		setModelData( doc, '<paragraph>f[]oo</paragraph>' );
+		setModelData( model, '<paragraph>f[]oo</paragraph>' );
 
 		button.fire( 'done', files );
 
 		const id = fileRepository.getLoader( files[ 0 ] ).id;
 
-		expect( getModelData( doc ) ).to.equal(
+		expect( getModelData( model ) ).to.equal(
 			`[<image uploadId="${ id }" uploadStatus="reading"></image>]` +
 			'<paragraph>foo</paragraph>'
 		);
@@ -109,14 +109,14 @@ describe( 'ImageUploadButton', () => {
 		const button = editor.ui.componentFactory.create( 'insertImage' );
 		const files = [ createNativeFileMock(), createNativeFileMock() ];
 
-		setModelData( doc, '<paragraph>foo[]</paragraph><paragraph>bar</paragraph>' );
+		setModelData( model, '<paragraph>foo[]</paragraph><paragraph>bar</paragraph>' );
 
 		button.fire( 'done', files );
 
 		const id1 = fileRepository.getLoader( files[ 0 ] ).id;
 		const id2 = fileRepository.getLoader( files[ 1 ] ).id;
 
-		expect( getModelData( doc ) ).to.equal(
+		expect( getModelData( model ) ).to.equal(
 			'<paragraph>foo</paragraph>' +
 			`<image uploadId="${ id1 }" uploadStatus="reading"></image>` +
 			`[<image uploadId="${ id2 }" uploadStatus="reading"></image>]` +

+ 25 - 24
packages/ckeditor5-upload/tests/imageuploadcommand.js

@@ -22,7 +22,7 @@ import log from '@ckeditor/ckeditor5-utils/src/log';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 
 describe( 'ImageUploadCommand', () => {
-	let editor, command, doc, fileRepository;
+	let editor, command, model, doc, fileRepository;
 
 	testUtils.createSinonSandbox();
 
@@ -42,11 +42,12 @@ describe( 'ImageUploadCommand', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-				command = new ImageUploadCommand( editor );
+				model = editor.model;
+				doc = model.document;
 
-				doc = editor.document;
+				command = new ImageUploadCommand( editor );
 
-				const schema = doc.schema;
+				const schema = model.schema;
 				schema.allow( { name: 'image', attributes: [ 'uploadId' ], inside: '$root' } );
 				schema.requireAttributes( 'image', [ 'uploadId' ] );
 			} );
@@ -59,57 +60,57 @@ describe( 'ImageUploadCommand', () => {
 	describe( 'execute()', () => {
 		it( 'should insert image at selection position (includes deleting selected content)', () => {
 			const file = createNativeFileMock();
-			setModelData( doc, '<paragraph>f[o]o</paragraph>' );
+			setModelData( model, '<paragraph>f[o]o</paragraph>' );
 
 			command.execute( { file } );
 
 			const id = fileRepository.getLoader( file ).id;
-			expect( getModelData( doc ) )
+			expect( getModelData( model ) )
 				.to.equal( `<paragraph>f</paragraph>[<image uploadId="${ id }"></image>]<paragraph>o</paragraph>` );
 		} );
 
 		it( 'should insert directly at specified position (options.insertAt)', () => {
 			const file = createNativeFileMock();
-			setModelData( doc, '<paragraph>f[]oo</paragraph>' );
+			setModelData( model, '<paragraph>f[]oo</paragraph>' );
 
 			const insertAt = new ModelPosition( doc.getRoot(), [ 0, 2 ] ); // fo[]o
 
 			command.execute( { file, insertAt } );
 
 			const id = fileRepository.getLoader( file ).id;
-			expect( getModelData( doc ) )
+			expect( getModelData( model ) )
 				.to.equal( `<paragraph>fo</paragraph>[<image uploadId="${ id }"></image>]<paragraph>o</paragraph>` );
 		} );
 
-		it( 'should allow to provide batch instance (options.batch)', () => {
-			const batch = doc.batch();
+		it( 'should use parent batch', () => {
 			const file = createNativeFileMock();
-			const spy = sinon.spy( batch, 'insert' );
 
-			setModelData( doc, '<paragraph>[]foo</paragraph>' );
+			setModelData( model, '<paragraph>[]foo</paragraph>' );
 
-			command.execute( { batch, file } );
-			const id = fileRepository.getLoader( file ).id;
+			model.change( writer => {
+				expect( writer.batch.deltas ).to.length( 0 );
 
-			expect( getModelData( doc ) ).to.equal( `[<image uploadId="${ id }"></image>]<paragraph>foo</paragraph>` );
-			sinon.assert.calledOnce( spy );
+				command.execute( { file } );
+
+				expect( writer.batch.deltas ).to.length.above( 0 );
+			} );
 		} );
 
 		it( 'should not insert image nor crash when image could not be inserted', () => {
 			const file = createNativeFileMock();
-			doc.schema.registerItem( 'other' );
-			doc.schema.allow( { name: '$text', inside: 'other' } );
-			doc.schema.allow( { name: 'other', inside: '$root' } );
-			doc.schema.limits.add( 'other' );
+			model.schema.registerItem( 'other' );
+			model.schema.allow( { name: '$text', inside: 'other' } );
+			model.schema.allow( { name: 'other', inside: '$root' } );
+			model.schema.limits.add( 'other' );
 			buildModelConverter().for( editor.editing.modelToView )
 				.fromElement( 'other' )
 				.toElement( 'p' );
 
-			setModelData( doc, '<other>[]</other>' );
+			setModelData( model, '<other>[]</other>' );
 
 			command.execute( { file } );
 
-			expect( getModelData( doc ) ).to.equal( '<other>[]</other>' );
+			expect( getModelData( model ) ).to.equal( '<other>[]</other>' );
 		} );
 
 		it( 'should not throw when upload adapter is not set (FileRepository will log an error anyway)', () => {
@@ -119,13 +120,13 @@ describe( 'ImageUploadCommand', () => {
 
 			const logStub = testUtils.sinon.stub( log, 'error' );
 
-			setModelData( doc, '<paragraph>fo[]o</paragraph>' );
+			setModelData( model, '<paragraph>fo[]o</paragraph>' );
 
 			expect( () => {
 				command.execute( { file } );
 			} ).to.not.throw();
 
-			expect( getModelData( doc ) ).to.equal( '<paragraph>fo[]o</paragraph>' );
+			expect( getModelData( model ) ).to.equal( '<paragraph>fo[]o</paragraph>' );
 			expect( logStub.calledOnce ).to.be.true;
 		} );
 	} );

+ 31 - 34
packages/ckeditor5-upload/tests/imageuploadengine.js

@@ -29,7 +29,7 @@ import Notification from '@ckeditor/ckeditor5-ui/src/notification/notification';
 describe( 'ImageUploadEngine', () => {
 	// eslint-disable-next-line max-len
 	const base64Sample = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=';
-	let editor, doc, fileRepository, viewDocument, nativeReaderMock, loader, adapterMock;
+	let editor, model, doc, fileRepository, viewDocument, nativeReaderMock, loader, adapterMock;
 
 	testUtils.createSinonSandbox();
 
@@ -58,13 +58,14 @@ describe( 'ImageUploadEngine', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-				doc = editor.document;
+				model = editor.model;
+				doc = model.document;
 				viewDocument = editor.editing.view;
 			} );
 	} );
 
 	it( 'should register proper schema rules', () => {
-		expect( doc.schema.check( { name: 'image', attributes: [ 'uploadId' ], inside: '$root' } ) ).to.be.true;
+		expect( model.schema.check( { name: 'image', attributes: [ 'uploadId' ], inside: '$root' } ) ).to.be.true;
 	} );
 
 	it( 'should register imageUpload command', () => {
@@ -75,7 +76,7 @@ describe( 'ImageUploadEngine', () => {
 		const spy = sinon.spy( editor, 'execute' );
 		const fileMock = createNativeFileMock();
 		const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
-		setModelData( doc, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 
 		const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
@@ -86,7 +87,7 @@ describe( 'ImageUploadEngine', () => {
 		sinon.assert.calledWith( spy, 'imageUpload' );
 
 		const id = fileRepository.getLoader( fileMock ).id;
-		expect( getModelData( doc ) ).to.equal(
+		expect( getModelData( model ) ).to.equal(
 			`<paragraph>foo</paragraph>[<image uploadId="${ id }" uploadStatus="reading"></image>]`
 		);
 	} );
@@ -95,7 +96,7 @@ describe( 'ImageUploadEngine', () => {
 		const spy = sinon.spy( editor, 'execute' );
 		const fileMock = createNativeFileMock();
 		const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
-		setModelData( doc, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 
 		const paragraph = doc.getRoot().getChild( 0 );
 		const targetRange = Range.createFromParentsAndOffsets( paragraph, 1, paragraph, 1 ); // f[]oo
@@ -107,7 +108,7 @@ describe( 'ImageUploadEngine', () => {
 		sinon.assert.calledWith( spy, 'imageUpload' );
 
 		const id = fileRepository.getLoader( fileMock ).id;
-		expect( getModelData( doc ) ).to.equal(
+		expect( getModelData( model ) ).to.equal(
 			`[<image uploadId="${ id }" uploadStatus="reading"></image>]<paragraph>foo</paragraph>`
 		);
 	} );
@@ -116,7 +117,7 @@ describe( 'ImageUploadEngine', () => {
 		const spy = sinon.spy( editor, 'execute' );
 		const files = [ createNativeFileMock(), createNativeFileMock() ];
 		const dataTransfer = new DataTransfer( { files, types: [ 'Files' ] } );
-		setModelData( doc, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 
 		const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
@@ -129,7 +130,7 @@ describe( 'ImageUploadEngine', () => {
 		const id1 = fileRepository.getLoader( files[ 0 ] ).id;
 		const id2 = fileRepository.getLoader( files[ 1 ] ).id;
 
-		expect( getModelData( doc ) ).to.equal(
+		expect( getModelData( model ) ).to.equal(
 			'<paragraph>foo</paragraph>' +
 			`<image uploadId="${ id1 }" uploadStatus="reading"></image>` +
 			`[<image uploadId="${ id2 }" uploadStatus="reading"></image>]`
@@ -145,7 +146,7 @@ describe( 'ImageUploadEngine', () => {
 		};
 		const dataTransfer = new DataTransfer( { files: [ fileMock ], types: [ 'Files' ] } );
 
-		setModelData( doc, '<paragraph>foo[]</paragraph>' );
+		setModelData( model, '<paragraph>foo[]</paragraph>' );
 
 		const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
@@ -163,7 +164,7 @@ describe( 'ImageUploadEngine', () => {
 			types: [ 'Files', 'text/html' ],
 			getData: type => type === 'text/html' ? '<p>SomeData</p>' : ''
 		} );
-		setModelData( doc, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 
 		const targetRange = Range.createFromParentsAndOffsets( doc.getRoot(), 1, doc.getRoot(), 1 );
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
@@ -184,7 +185,7 @@ describe( 'ImageUploadEngine', () => {
 			types: typesDomStringListMock,
 			getData: type => type === 'text/html' ? '<p>SomeData</p>' : 'SomeData'
 		} );
-		setModelData( doc, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 
 		const targetRange = doc.selection.getFirstRange();
 		const targetViewRange = editor.editing.mapper.toViewRange( targetRange );
@@ -192,7 +193,7 @@ describe( 'ImageUploadEngine', () => {
 		viewDocument.fire( 'clipboardInput', { dataTransfer, targetRanges: [ targetViewRange ] } );
 
 		// Well, there's no clipboard plugin, so nothing happens.
-		expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo</paragraph>' );
+		expect( getModelData( model ) ).to.equal( '<paragraph>[]foo</paragraph>' );
 	} );
 
 	it( 'should not convert image\'s uploadId attribute if is consumed already', () => {
@@ -200,7 +201,7 @@ describe( 'ImageUploadEngine', () => {
 			consumable.consume( data.item, eventNameToConsumableType( evt.name ) );
 		}, { priority: 'high' } );
 
-		setModelData( doc, '<image uploadId="1234"></image>' );
+		setModelData( model, '<image uploadId="1234"></image>' );
 
 		expect( getViewData( viewDocument ) ).to.equal(
 			'[<figure class="ck-widget image" contenteditable="false">' +
@@ -210,7 +211,7 @@ describe( 'ImageUploadEngine', () => {
 
 	it( 'should use read data once it is present', done => {
 		const file = createNativeFileMock();
-		setModelData( doc, '<paragraph>{}foo bar</paragraph>' );
+		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 		editor.execute( 'imageUpload', { file } );
 
 		doc.once( 'changesDone', () => {
@@ -230,7 +231,7 @@ describe( 'ImageUploadEngine', () => {
 
 	it( 'should replace read data with server response once it is present', done => {
 		const file = createNativeFileMock();
-		setModelData( doc, '<paragraph>{}foo bar</paragraph>' );
+		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 		editor.execute( 'imageUpload', { file } );
 
 		doc.once( 'changesDone', () => {
@@ -261,7 +262,7 @@ describe( 'ImageUploadEngine', () => {
 			done();
 		}, { priority: 'high' } );
 
-		setModelData( doc, '<paragraph>{}foo bar</paragraph>' );
+		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 		editor.execute( 'imageUpload', { file } );
 
 		nativeReaderMock.mockError( 'Reading error.' );
@@ -277,7 +278,7 @@ describe( 'ImageUploadEngine', () => {
 			evt.stop();
 		}, { priority: 'high' } );
 
-		setModelData( doc, '<paragraph>{}foo bar</paragraph>' );
+		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 		editor.execute( 'imageUpload', { file } );
 		nativeReaderMock.abort();
 
@@ -288,7 +289,7 @@ describe( 'ImageUploadEngine', () => {
 	} );
 
 	it( 'should do nothing if image does not have uploadId', () => {
-		setModelData( doc, '<image src="image.png"></image>' );
+		setModelData( model, '<image src="image.png"></image>' );
 
 		expect( getViewData( viewDocument ) ).to.equal(
 			'[<figure class="ck-widget image" contenteditable="false"><img src="image.png"></img></figure>]'
@@ -299,7 +300,7 @@ describe( 'ImageUploadEngine', () => {
 		const file = createNativeFileMock();
 		const spy = testUtils.sinon.spy();
 		const notification = editor.plugins.get( Notification );
-		setModelData( doc, '<paragraph>{}foo bar</paragraph>' );
+		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 
 		notification.on( 'show:warning', evt => {
 			spy();
@@ -310,7 +311,7 @@ describe( 'ImageUploadEngine', () => {
 
 		doc.once( 'changesDone', () => {
 			doc.once( 'changesDone', () => {
-				expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
+				expect( getModelData( model ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
 				sinon.assert.calledOnce( spy );
 
 				done();
@@ -322,7 +323,7 @@ describe( 'ImageUploadEngine', () => {
 
 	it( 'should abort upload if image is removed', () => {
 		const file = createNativeFileMock();
-		setModelData( doc, '<paragraph>{}foo bar</paragraph>' );
+		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 		editor.execute( 'imageUpload', { file } );
 		const abortSpy = testUtils.sinon.spy( loader, 'abort' );
 
@@ -330,10 +331,8 @@ describe( 'ImageUploadEngine', () => {
 		nativeReaderMock.mockSuccess( base64Sample );
 
 		const image = doc.getRoot().getChild( 0 );
-		doc.enqueueChanges( () => {
-			const batch = doc.batch();
-
-			batch.remove( image );
+		model.change( writer => {
+			writer.remove( image );
 		} );
 
 		expect( loader.status ).to.equal( 'aborted' );
@@ -343,7 +342,7 @@ describe( 'ImageUploadEngine', () => {
 	it( 'image should be permanently removed if it is removed by user during upload', done => {
 		const file = createNativeFileMock();
 		const notification = editor.plugins.get( Notification );
-		setModelData( doc, '<paragraph>{}foo bar</paragraph>' );
+		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 
 		// Prevent popping up alert window.
 		notification.on( 'show:warning', evt => {
@@ -363,12 +362,12 @@ describe( 'ImageUploadEngine', () => {
 						undone = true;
 
 						// This is called after abort remove.
-						expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
+						expect( getModelData( model ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
 
 						editor.execute( 'undo' );
 
 						// Expect that the image has not been brought back.
-						expect( getModelData( doc ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
+						expect( getModelData( model ) ).to.equal( '<paragraph>[]foo bar</paragraph>' );
 
 						done();
 					}
@@ -377,16 +376,14 @@ describe( 'ImageUploadEngine', () => {
 		} );
 
 		const image = doc.getRoot().getChild( 0 );
-		doc.enqueueChanges( () => {
-			const batch = doc.batch();
-
-			batch.remove( image );
+		model.change( writer => {
+			writer.remove( image );
 		} );
 	} );
 
 	it( 'should create responsive image if server return multiple images', done => {
 		const file = createNativeFileMock();
-		setModelData( doc, '<paragraph>{}foo bar</paragraph>' );
+		setModelData( model, '<paragraph>{}foo bar</paragraph>' );
 		editor.execute( 'imageUpload', { file } );
 
 		doc.once( 'changesDone', () => {

+ 14 - 13
packages/ckeditor5-upload/tests/imageuploadprogress.js

@@ -26,7 +26,7 @@ describe( 'ImageUploadProgress', () => {
 
 	// eslint-disable-next-line max-len
 	const base64Sample = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=';
-	let editor, document, fileRepository, viewDocument, nativeReaderMock, loader, adapterMock;
+	let editor, model, document, fileRepository, viewDocument, nativeReaderMock, loader, adapterMock;
 
 	class UploadAdapterPluginMock extends Plugin {
 		init() {
@@ -55,7 +55,8 @@ describe( 'ImageUploadProgress', () => {
 			} )
 			.then( newEditor => {
 				editor = newEditor;
-				document = editor.document;
+				model = editor.model;
+				document = model.document;
 				viewDocument = editor.editing.view;
 
 				fileRepository = editor.plugins.get( FileRepository );
@@ -73,7 +74,7 @@ describe( 'ImageUploadProgress', () => {
 	} );
 
 	it( 'should convert image\'s "reading" uploadStatus attribute', () => {
-		setModelData( document, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 		editor.execute( 'imageUpload', { file: createNativeFileMock() } );
 
 		expect( getViewData( viewDocument ) ).to.equal(
@@ -84,7 +85,7 @@ describe( 'ImageUploadProgress', () => {
 	} );
 
 	it( 'should convert image\'s "uploading" uploadStatus attribute', done => {
-		setModelData( document, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 		editor.execute( 'imageUpload', { file: createNativeFileMock() } );
 
 		document.once( 'changesDone', () => {
@@ -102,7 +103,7 @@ describe( 'ImageUploadProgress', () => {
 	} );
 
 	it( 'should update progressbar width on progress', done => {
-		setModelData( document, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 		editor.execute( 'imageUpload', { file: createNativeFileMock() } );
 
 		document.once( 'changesDone', () => {
@@ -122,7 +123,7 @@ describe( 'ImageUploadProgress', () => {
 	} );
 
 	it( 'should convert image\'s "complete" uploadStatus attribute', done => {
-		setModelData( document, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 		editor.execute( 'imageUpload', { file: createNativeFileMock() } );
 
 		document.once( 'changesDone', () => {
@@ -146,7 +147,7 @@ describe( 'ImageUploadProgress', () => {
 		const uploadProgress = editor.plugins.get( ImageUploadProgress );
 		uploadProgress.placeholder = base64Sample;
 
-		setModelData( document, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 		editor.execute( 'imageUpload', { file: createNativeFileMock() } );
 
 		expect( getViewData( viewDocument ) ).to.equal(
@@ -161,7 +162,7 @@ describe( 'ImageUploadProgress', () => {
 			consumable.consume( data.item, eventNameToConsumableType( evt.name ) );
 		}, { priority: 'highest' } );
 
-		setModelData( document, '<paragraph>[]foo</paragraph>' );
+		setModelData( model, '<paragraph>[]foo</paragraph>' );
 		editor.execute( 'imageUpload', { file: createNativeFileMock() } );
 
 		expect( getViewData( viewDocument ) ).to.equal(
@@ -170,12 +171,12 @@ describe( 'ImageUploadProgress', () => {
 	} );
 
 	it( 'should not show progress bar if there is no loader with given uploadId', () => {
-		setModelData( document, '<image uploadId="123" uploadStatus="reading"></image>' );
+		setModelData( model, '<image uploadId="123" uploadStatus="reading"></image>' );
 
 		const image = document.getRoot().getChild( 0 );
 
-		document.enqueueChanges( () => {
-			document.batch().setAttribute( 'uploadStatus', 'uploading', image );
+		model.change( writer => {
+			writer.setAttribute( 'uploadStatus', 'uploading', image );
 		} );
 
 		expect( getViewData( viewDocument ) ).to.equal(
@@ -184,8 +185,8 @@ describe( 'ImageUploadProgress', () => {
 			'</figure>]'
 		);
 
-		document.enqueueChanges( () => {
-			document.batch().setAttribute( 'uploadStatus', 'complete', image );
+		model.change( writer => {
+			writer.setAttribute( 'uploadStatus', 'complete', image );
 		} );
 
 		expect( getViewData( viewDocument ) ).to.equal(

+ 19 - 18
packages/ckeditor5-upload/tests/utils.js

@@ -4,7 +4,7 @@
  */
 
 import { isImageType, findOptimalInsertionPosition } from '../src/utils';
-import Document from '@ckeditor/ckeditor5-engine/src/model/document';
+import Model from '@ckeditor/ckeditor5-engine/src/model/model';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'upload utils', () => {
@@ -32,26 +32,27 @@ describe( 'upload utils', () => {
 	} );
 
 	describe( 'findOptimalInsertionPosition()', () => {
-		let doc;
+		let model, doc;
 
 		beforeEach( () => {
-			doc = new Document();
+			model = new Model();
+			doc = model.document;
 
 			doc.createRoot();
 
-			doc.schema.registerItem( 'paragraph', '$block' );
-			doc.schema.registerItem( 'image' );
-			doc.schema.registerItem( 'span' );
+			model.schema.registerItem( 'paragraph', '$block' );
+			model.schema.registerItem( 'image' );
+			model.schema.registerItem( 'span' );
 
-			doc.schema.allow( { name: 'image', inside: '$root' } );
-			doc.schema.objects.add( 'image' );
+			model.schema.allow( { name: 'image', inside: '$root' } );
+			model.schema.objects.add( 'image' );
 
-			doc.schema.allow( { name: 'span', inside: 'paragraph' } );
-			doc.schema.allow( { name: '$text', inside: 'span' } );
+			model.schema.allow( { name: 'span', inside: 'paragraph' } );
+			model.schema.allow( { name: '$text', inside: 'span' } );
 		} );
 
 		it( 'returns position after selected element', () => {
-			setData( doc, '<paragraph>x</paragraph>[<image></image>]<paragraph>y</paragraph>' );
+			setData( model, '<paragraph>x</paragraph>[<image></image>]<paragraph>y</paragraph>' );
 
 			const pos = findOptimalInsertionPosition( doc.selection );
 
@@ -59,7 +60,7 @@ describe( 'upload utils', () => {
 		} );
 
 		it( 'returns position inside empty block', () => {
-			setData( doc, '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>y</paragraph>' );
+			setData( model, '<paragraph>x</paragraph><paragraph>[]</paragraph><paragraph>y</paragraph>' );
 
 			const pos = findOptimalInsertionPosition( doc.selection );
 
@@ -67,7 +68,7 @@ describe( 'upload utils', () => {
 		} );
 
 		it( 'returns position before block if at the beginning of that block', () => {
-			setData( doc, '<paragraph>x</paragraph><paragraph>[]foo</paragraph><paragraph>y</paragraph>' );
+			setData( model, '<paragraph>x</paragraph><paragraph>[]foo</paragraph><paragraph>y</paragraph>' );
 
 			const pos = findOptimalInsertionPosition( doc.selection );
 
@@ -75,7 +76,7 @@ describe( 'upload utils', () => {
 		} );
 
 		it( 'returns position before block if in the middle of that block', () => {
-			setData( doc, '<paragraph>x</paragraph><paragraph>f[]oo</paragraph><paragraph>y</paragraph>' );
+			setData( model, '<paragraph>x</paragraph><paragraph>f[]oo</paragraph><paragraph>y</paragraph>' );
 
 			const pos = findOptimalInsertionPosition( doc.selection );
 
@@ -83,7 +84,7 @@ describe( 'upload utils', () => {
 		} );
 
 		it( 'returns position after block if at the end of that block', () => {
-			setData( doc, '<paragraph>x</paragraph><paragraph>foo[]</paragraph><paragraph>y</paragraph>' );
+			setData( model, '<paragraph>x</paragraph><paragraph>foo[]</paragraph><paragraph>y</paragraph>' );
 
 			const pos = findOptimalInsertionPosition( doc.selection );
 
@@ -92,7 +93,7 @@ describe( 'upload utils', () => {
 
 		// Checking if isTouching() was used.
 		it( 'returns position after block if at the end of that block (deeply nested)', () => {
-			setData( doc, '<paragraph>x</paragraph><paragraph>foo<span>bar[]</span></paragraph><paragraph>y</paragraph>' );
+			setData( model, '<paragraph>x</paragraph><paragraph>foo<span>bar[]</span></paragraph><paragraph>y</paragraph>' );
 
 			const pos = findOptimalInsertionPosition( doc.selection );
 
@@ -100,8 +101,8 @@ describe( 'upload utils', () => {
 		} );
 
 		it( 'returns selection focus if not in a block', () => {
-			doc.schema.allow( { name: '$text', inside: '$root' } );
-			setData( doc, 'foo[]bar' );
+			model.schema.allow( { name: '$text', inside: '$root' } );
+			setData( model, 'foo[]bar' );
 
 			const pos = findOptimalInsertionPosition( doc.selection );