浏览代码

Aligned test with engine changes.

Oskar Wróbel 8 年之前
父节点
当前提交
4eea57c519

+ 131 - 130
packages/ckeditor5-autoformat/tests/autoformat.js

@@ -24,7 +24,7 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
 testUtils.createSinonSandbox();
 testUtils.createSinonSandbox();
 
 
 describe( 'Autoformat', () => {
 describe( 'Autoformat', () => {
-	let editor, doc, batch;
+	let editor, model, doc;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 		return VirtualTestEditor
@@ -43,8 +43,8 @@ describe( 'Autoformat', () => {
 			} )
 			} )
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				doc = editor.document;
-				batch = doc.batch();
+				model = editor.model;
+				doc = model.document;
 			} );
 			} );
 	} );
 	} );
 
 
@@ -54,97 +54,97 @@ describe( 'Autoformat', () => {
 
 
 	describe( 'Bulleted list', () => {
 	describe( 'Bulleted list', () => {
 		it( 'should replace asterisk with bulleted list item', () => {
 		it( 'should replace asterisk with bulleted list item', () => {
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
 		} );
 		} );
 
 
 		it( 'should replace minus character with bulleted list item', () => {
 		it( 'should replace minus character with bulleted list item', () => {
-			setData( doc, '<paragraph>-[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>-[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">[]</listItem>' );
 		} );
 		} );
 
 
 		it( 'should not replace minus character when inside bulleted list item', () => {
 		it( 'should not replace minus character when inside bulleted list item', () => {
-			setData( doc, '<listItem indent="0" type="bulleted">-[]</listItem>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<listItem indent="0" type="bulleted">-[]</listItem>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">- []</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">- []</listItem>' );
 		} );
 		} );
 	} );
 	} );
 
 
 	describe( 'Numbered list', () => {
 	describe( 'Numbered list', () => {
 		it( 'should replace digit with numbered list item using the dot format', () => {
 		it( 'should replace digit with numbered list item using the dot format', () => {
-			setData( doc, '<paragraph>1.[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>1.[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
 		} );
 		} );
 
 
 		it( 'should replace digit with numbered list item using the parenthesis format', () => {
 		it( 'should replace digit with numbered list item using the parenthesis format', () => {
-			setData( doc, '<paragraph>1)[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>1)[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
 		} );
 		} );
 
 
 		it( 'should not replace digit character when there is no . or ) in the format', () => {
 		it( 'should not replace digit character when there is no . or ) in the format', () => {
-			setData( doc, '<paragraph>1[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>1[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>1 []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>1 []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace digit character when inside numbered list item', () => {
 		it( 'should not replace digit character when inside numbered list item', () => {
-			setData( doc, '<listItem indent="0" type="numbered">1.[]</listItem>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<listItem indent="0" type="numbered">1.[]</listItem>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. []</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">1. []</listItem>' );
 		} );
 		} );
 	} );
 	} );
 
 
 	describe( 'Heading', () => {
 	describe( 'Heading', () => {
 		it( 'should replace hash character with heading', () => {
 		it( 'should replace hash character with heading', () => {
-			setData( doc, '<paragraph>#[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>#[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<heading1>[]</heading1>' );
+			expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
 		} );
 		} );
 
 
 		it( 'should replace two hash characters with heading level 2', () => {
 		it( 'should replace two hash characters with heading level 2', () => {
-			setData( doc, '<paragraph>##[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>##[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<heading2>[]</heading2>' );
+			expect( getData( model ) ).to.equal( '<heading2>[]</heading2>' );
 		} );
 		} );
 
 
 		it( 'should not replace hash character when inside heading', () => {
 		it( 'should not replace hash character when inside heading', () => {
-			setData( doc, '<heading1>#[]</heading1>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<heading1>#[]</heading1>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<heading1># []</heading1>' );
+			expect( getData( model ) ).to.equal( '<heading1># []</heading1>' );
 		} );
 		} );
 
 
 		it( 'should work with heading1-heading6 commands regardless of the config of the heading feature', () => {
 		it( 'should work with heading1-heading6 commands regardless of the config of the heading feature', () => {
@@ -174,18 +174,19 @@ describe( 'Autoformat', () => {
 					]
 					]
 				} )
 				} )
 				.then( editor => {
 				.then( editor => {
-					const doc = editor.document;
+					const model = editor.model;
+					const doc = model.document;
 
 
-					setData( doc, '<paragraph>#[]</paragraph>' );
-					doc.enqueueChanges( () => {
-						doc.batch().insertText( ' ', doc.selection.getFirstPosition() );
+					setData( model, '<paragraph>#[]</paragraph>' );
+					model.change( writer => {
+						writer.insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 					} );
 
 
 					expect( spy1.calledOnce ).to.be.true;
 					expect( spy1.calledOnce ).to.be.true;
 
 
-					setData( doc, '<paragraph>######[]</paragraph>' );
-					doc.enqueueChanges( () => {
-						doc.batch().insertText( ' ', doc.selection.getFirstPosition() );
+					setData( model, '<paragraph>######[]</paragraph>' );
+					model.change( writer => {
+						writer.insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 					} );
 
 
 					expect( spy6.calledOnce ).to.be.true;
 					expect( spy6.calledOnce ).to.be.true;
@@ -197,86 +198,86 @@ describe( 'Autoformat', () => {
 
 
 	describe( 'Block quote', () => {
 	describe( 'Block quote', () => {
 		it( 'should replace greater-than character with heading', () => {
 		it( 'should replace greater-than character with heading', () => {
-			setData( doc, '<paragraph>>[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>>[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
+			expect( getData( model ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
 		} );
 		} );
 
 
 		it( 'should not replace greater-than character when inside heading', () => {
 		it( 'should not replace greater-than character when inside heading', () => {
-			setData( doc, '<heading1>>[]</heading1>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<heading1>>[]</heading1>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<heading1>> []</heading1>' );
+			expect( getData( model ) ).to.equal( '<heading1>> []</heading1>' );
 		} );
 		} );
 
 
 		it( 'should not replace greater-than character when inside numbered list', () => {
 		it( 'should not replace greater-than character when inside numbered list', () => {
-			setData( doc, '<listItem indent="0" type="numbered">1. >[]</listItem>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<listItem indent="0" type="numbered">1. >[]</listItem>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. > []</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="numbered">1. > []</listItem>' );
 		} );
 		} );
 
 
 		it( 'should not replace greater-than character when inside buletted list', () => {
 		it( 'should not replace greater-than character when inside buletted list', () => {
-			setData( doc, '<listItem indent="0" type="bulleted">1. >[]</listItem>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<listItem indent="0" type="bulleted">1. >[]</listItem>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">1. > []</listItem>' );
+			expect( getData( model ) ).to.equal( '<listItem indent="0" type="bulleted">1. > []</listItem>' );
 		} );
 		} );
 	} );
 	} );
 
 
 	describe( 'Inline autoformat', () => {
 	describe( 'Inline autoformat', () => {
 		it( 'should replace both "**" with bold', () => {
 		it( 'should replace both "**" with bold', () => {
-			setData( doc, '<paragraph>**foobar*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>**foobar*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph><$text bold="true">foobar</$text>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph><$text bold="true">foobar</$text>[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should replace both "*" with italic', () => {
 		it( 'should replace both "*" with italic', () => {
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph><$text italic="true">foobar</$text>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph><$text italic="true">foobar</$text>[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should replace both "`" with code', () => {
 		it( 'should replace both "`" with code', () => {
-			setData( doc, '<paragraph>`foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '`', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>`foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '`', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph><$text code="true">foobar</$text>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph><$text code="true">foobar</$text>[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'nothing should be replaces when typing "*"', () => {
 		it( 'nothing should be replaces when typing "*"', () => {
-			setData( doc, '<paragraph>foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>foobar*[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>foobar*[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should format inside the text', () => {
 		it( 'should format inside the text', () => {
-			setData( doc, '<paragraph>foo **bar*[] baz</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>foo **bar*[] baz</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>foo <$text bold="true">bar</$text>[] baz</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>foo <$text bold="true">bar</$text>[] baz</paragraph>' );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -288,90 +289,90 @@ describe( 'Autoformat', () => {
 				} )
 				} )
 				.then( newEditor => {
 				.then( newEditor => {
 					editor = newEditor;
 					editor = newEditor;
-					doc = editor.document;
-					batch = doc.batch();
+					model = editor.model;
+					doc = model.document;
 				} );
 				} );
 		} );
 		} );
 
 
 		it( 'should not replace asterisk with bulleted list item', () => {
 		it( 'should not replace asterisk with bulleted list item', () => {
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>* []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>* []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace minus character with bulleted list item', () => {
 		it( 'should not replace minus character with bulleted list item', () => {
-			setData( doc, '<paragraph>-[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>-[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>- []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>- []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace digit with numbered list item', () => {
 		it( 'should not replace digit with numbered list item', () => {
-			setData( doc, '<paragraph>1.[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>1.[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>1. []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>1. []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace hash character with heading', () => {
 		it( 'should not replace hash character with heading', () => {
-			setData( doc, '<paragraph>#[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>#[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph># []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph># []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace two hash characters with heading level 2', () => {
 		it( 'should not replace two hash characters with heading level 2', () => {
-			setData( doc, '<paragraph>##[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>##[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>## []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>## []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace both "**" with bold', () => {
 		it( 'should not replace both "**" with bold', () => {
-			setData( doc, '<paragraph>**foobar*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>**foobar*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>**foobar**[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>**foobar**[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace both "*" with italic', () => {
 		it( 'should not replace both "*" with italic', () => {
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace both "`" with code', () => {
 		it( 'should not replace both "`" with code', () => {
-			setData( doc, '<paragraph>`foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '`', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>`foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '`', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>`foobar`[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>`foobar`[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not replace ">" with block quote', () => {
 		it( 'should not replace ">" with block quote', () => {
-			setData( doc, '<paragraph>>[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>>[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>> []</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>> []</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should use only configured headings', () => {
 		it( 'should use only configured headings', () => {
@@ -386,15 +387,15 @@ describe( 'Autoformat', () => {
 					}
 					}
 				} )
 				} )
 				.then( editor => {
 				.then( editor => {
-					doc = editor.document;
-					batch = doc.batch();
+					model = editor.model;
+					doc = model.document;
 
 
-					setData( doc, '<paragraph>##[]</paragraph>' );
-					doc.enqueueChanges( () => {
-						batch.insertText( ' ', doc.selection.getFirstPosition() );
+					setData( model, '<paragraph>##[]</paragraph>' );
+					model.change( writer => {
+						writer.insertText( ' ', doc.selection.getFirstPosition() );
 					} );
 					} );
 
 
-					expect( getData( doc ) ).to.equal( '<paragraph>## []</paragraph>' );
+					expect( getData( model ) ).to.equal( '<paragraph>## []</paragraph>' );
 				} );
 				} );
 		} );
 		} );
 	} );
 	} );

+ 25 - 25
packages/ckeditor5-autoformat/tests/blockautoformatengine.js

@@ -14,7 +14,7 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
 testUtils.createSinonSandbox();
 testUtils.createSinonSandbox();
 
 
 describe( 'BlockAutoformatEngine', () => {
 describe( 'BlockAutoformatEngine', () => {
-	let editor, doc, batch;
+	let editor, model, doc;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 		return VirtualTestEditor
@@ -23,8 +23,8 @@ describe( 'BlockAutoformatEngine', () => {
 			} )
 			} )
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				doc = editor.document;
-				batch = doc.batch();
+				model = editor.model;
+				doc = model.document;
 			} );
 			} );
 	} );
 	} );
 
 
@@ -34,9 +34,9 @@ describe( 'BlockAutoformatEngine', () => {
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledOnce( spy );
@@ -47,9 +47,9 @@ describe( 'BlockAutoformatEngine', () => {
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
@@ -60,13 +60,13 @@ describe( 'BlockAutoformatEngine', () => {
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			editor.commands.add( 'testCommand', new TestCommand( editor, spy ) );
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledOnce( spy );
-			expect( getData( doc ) ).to.equal( '<paragraph>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>[]</paragraph>' );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -75,9 +75,9 @@ describe( 'BlockAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.calledOnce( spy );
 			sinon.assert.calledOnce( spy );
@@ -87,9 +87,9 @@ describe( 'BlockAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
@@ -99,9 +99,9 @@ describe( 'BlockAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.remove( doc.selection.getFirstRange() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.remove( doc.selection.getFirstRange() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
@@ -111,9 +111,9 @@ describe( 'BlockAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );

+ 36 - 36
packages/ckeditor5-autoformat/tests/inlineautoformatengine.js

@@ -13,7 +13,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 testUtils.createSinonSandbox();
 testUtils.createSinonSandbox();
 
 
 describe( 'InlineAutoformatEngine', () => {
 describe( 'InlineAutoformatEngine', () => {
-	let editor, doc, batch;
+	let editor, model, doc;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return VirtualTestEditor
 		return VirtualTestEditor
@@ -22,9 +22,9 @@ describe( 'InlineAutoformatEngine', () => {
 			} )
 			} )
 			.then( newEditor => {
 			.then( newEditor => {
 				editor = newEditor;
 				editor = newEditor;
-				doc = editor.document;
-				batch = doc.batch();
-				doc.schema.allow( { name: '$inline', attributes: [ 'testAttribute' ] } );
+				model = editor.model;
+				doc = model.document;
+				model.schema.allow( { name: '$inline', attributes: [ 'testAttribute' ] } );
 			} );
 			} );
 	} );
 	} );
 
 
@@ -32,45 +32,45 @@ describe( 'InlineAutoformatEngine', () => {
 		it( 'should stop early if there are less than 3 capture groups', () => {
 		it( 'should stop early if there are less than 3 capture groups', () => {
 			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should apply an attribute when the pattern is matched', () => {
 		it( 'should apply an attribute when the pattern is matched', () => {
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph><$text testAttribute="true">foobar</$text>[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph><$text testAttribute="true">foobar</$text>[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should not apply an attribute when changes are in transparent batch', () => {
 		it( 'should not apply an attribute when changes are in transparent batch', () => {
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
 		} );
 		} );
 
 
 		it( 'should stop early if selection is not collapsed', () => {
 		it( 'should stop early if selection is not collapsed', () => {
 			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foob[ar]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foob[ar]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
-			expect( getData( doc ) ).to.equal( '<paragraph>*foob*[ar]</paragraph>' );
+			expect( getData( model ) ).to.equal( '<paragraph>*foob*[ar]</paragraph>' );
 		} );
 		} );
 	} );
 	} );
 
 
@@ -79,9 +79,9 @@ describe( 'InlineAutoformatEngine', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, spy ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, spy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				doc.batch( 'transparent' ).insertText( '*', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
+			model.enqueueChange( 'transparent', writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( spy );
 			sinon.assert.notCalled( spy );
@@ -96,9 +96,9 @@ describe( 'InlineAutoformatEngine', () => {
 
 
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( formatSpy );
 			sinon.assert.notCalled( formatSpy );
@@ -113,9 +113,9 @@ describe( 'InlineAutoformatEngine', () => {
 
 
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>*[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( formatSpy );
 			sinon.assert.notCalled( formatSpy );
@@ -130,9 +130,9 @@ describe( 'InlineAutoformatEngine', () => {
 
 
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>[]</paragraph>' );
-			doc.enqueueChanges( () => {
-				batch.insertText( ' ', doc.selection.getFirstPosition() );
+			setData( model, '<paragraph>[]</paragraph>' );
+			model.change( writer => {
+				writer.insertText( ' ', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			sinon.assert.notCalled( formatSpy );
 			sinon.assert.notCalled( formatSpy );
@@ -141,16 +141,16 @@ describe( 'InlineAutoformatEngine', () => {
 		it( 'should detach removed ranges', () => {
 		it( 'should detach removed ranges', () => {
 			const detachSpies = [];
 			const detachSpies = [];
 			const callback = fixBatch => testUtils.sinon.stub( fixBatch, 'remove' ).callsFake( saveDetachSpy );
 			const callback = fixBatch => testUtils.sinon.stub( fixBatch, 'remove' ).callsFake( saveDetachSpy );
-			testUtils.sinon.stub( editor.document.schema, 'getValidRanges' )
+			testUtils.sinon.stub( editor.model.schema, 'getValidRanges' )
 				.callThrough()
 				.callThrough()
 				.callsFake( ranges => ranges.map( saveDetachSpy ) );
 				.callsFake( ranges => ranges.map( saveDetachSpy ) );
 
 
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, callback ); // eslint-disable-line no-new
 			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, callback ); // eslint-disable-line no-new
 
 
-			setData( doc, '<paragraph>*foobar[]</paragraph>' );
+			setData( model, '<paragraph>*foobar[]</paragraph>' );
 
 
-			doc.enqueueChanges( () => {
-				doc.batch().insertText( '*', doc.selection.getFirstPosition() );
+			model.change( writer => {
+				writer.insertText( '*', doc.selection.getFirstPosition() );
 			} );
 			} );
 
 
 			// There should be two removed ranges and one range used to apply autoformat.
 			// There should be two removed ranges and one range used to apply autoformat.