浏览代码

Merge branch 'master' into t/61

Piotrek Koszuliński 8 年之前
父节点
当前提交
5ad17e0cec
共有 2 个文件被更改,包括 18 次插入19 次删除
  1. 8 3
      packages/ckeditor5-typing/tests/deletecommand.js
  2. 10 16
      packages/ckeditor5-typing/tests/inputcommand.js

+ 8 - 3
packages/ckeditor5-typing/tests/deletecommand.js

@@ -41,11 +41,16 @@ describe( 'DeleteCommand', () => {
 		it( 'uses enqueueChanges', () => {
 			setData( doc, '<paragraph>foo[]bar</paragraph>' );
 
-			const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );
+			doc.enqueueChanges( () => {
+				editor.execute( 'delete' );
 
-			editor.execute( 'delete' );
+				// We expect that command is executed in enqueue changes block. Since we are already in
+				// an enqueued block, the command execution will be postponed. Hence, no changes.
+				expect( getData( doc ) ).to.equal( '<p>foo[]bar</p>' );
+			} );
 
-			expect( spy.calledOnce ).to.be.true;
+			// After all enqueued changes are done, the command execution is reflected.
+			expect( getData( doc ) ).to.equal( '<p>fo[]bar</p>' );
 		} );
 
 		it( 'locks buffer when executing', () => {

+ 10 - 16
packages/ckeditor5-typing/tests/inputcommand.js

@@ -18,7 +18,7 @@ describe( 'InputCommand', () => {
 
 	testUtils.createSinonSandbox();
 
-	before( () => {
+	beforeEach( () => {
 		return ModelTestEditor.create()
 			.then( newEditor => {
 				editor = newEditor;
@@ -28,20 +28,17 @@ describe( 'InputCommand', () => {
 				editor.commands.add( 'input', inputCommand );
 
 				buffer = inputCommand.buffer;
+				buffer.size = 0;
 
 				doc.schema.registerItem( 'p', '$block' );
 				doc.schema.registerItem( 'h1', '$block' );
 			} );
 	} );
 
-	after( () => {
+	afterEach( () => {
 		return editor.destroy();
 	} );
 
-	beforeEach( () => {
-		buffer.size = 0;
-	} );
-
 	describe( 'buffer', () => {
 		it( 'has buffer getter', () => {
 			expect( editor.commands.get( 'input' ).buffer ).to.be.an.instanceof( ChangeBuffer );
@@ -69,13 +66,16 @@ describe( 'InputCommand', () => {
 		it( 'uses enqueueChanges', () => {
 			setData( doc, '<p>foo[]bar</p>' );
 
-			const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );
+			doc.enqueueChanges( () => {
+				editor.execute( 'input', { text: 'x' } );
 
-			editor.execute( 'input', {
-				text: ''
+				// We expect that command is executed in enqueue changes block. Since we are already in
+				// an enqueued block, the command execution will be postponed. Hence, no changes.
+				expect( getData( doc ) ).to.be.equal( '<p>foo[]bar</p>' );
 			} );
 
-			expect( spy.calledOnce ).to.be.true;
+			// After all enqueued changes are done, the command execution is reflected.
+			expect( getData( doc ) ).to.be.equal( '<p>foox[]bar</p>' );
 		} );
 
 		it( 'should lock and unlock buffer', () => {
@@ -202,11 +202,8 @@ describe( 'InputCommand', () => {
 		it( 'only removes content when no text given (with default non-collapsed range)', () => {
 			setData( doc, '<p>[fo]obar</p>' );
 
-			const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );
-
 			editor.execute( 'input' );
 
-			expect( spy.callCount ).to.be.equal( 1 );
 			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>[]obar</p>' );
 			expect( buffer.size ).to.be.equal( 0 );
 		} );
@@ -214,11 +211,8 @@ describe( 'InputCommand', () => {
 		it( 'does not change selection and content when no text given (with default collapsed range)', () => {
 			setData( doc, '<p>fo[]obar</p>' );
 
-			const spy = testUtils.sinon.spy( doc, 'enqueueChanges' );
-
 			editor.execute( 'input' );
 
-			expect( spy.callCount ).to.be.equal( 1 );
 			expect( getData( doc, { selection: true } ) ).to.be.equal( '<p>fo[]obar</p>' );
 			expect( buffer.size ).to.be.equal( 0 );
 		} );