8
0
فهرست منبع

Tests: Added tests to make sure the List feature is properly integrated with the KeystrokeHandler.

Aleksander Nowodzinski 8 سال پیش
والد
کامیت
29ec7821bb
2فایلهای تغییر یافته به همراه14 افزوده شده و 6 حذف شده
  1. 1 2
      packages/ckeditor5-list/src/list.js
  2. 13 4
      packages/ckeditor5-list/tests/list.js

+ 1 - 2
packages/ckeditor5-list/src/list.js

@@ -67,9 +67,8 @@ export default class List extends Plugin {
 
 				if ( command.isEnabled ) {
 					this.editor.execute( commandName );
+					cancel();
 				}
-
-				cancel();
 			};
 		};
 

+ 13 - 4
packages/ckeditor5-list/tests/list.js

@@ -121,8 +121,9 @@ describe( 'List', () => {
 
 		beforeEach( () => {
 			domEvtDataStub = {
-				keystroke: getCode( 'Tab' ),
-				preventDefault() {}
+				keyCode: getCode( 'Tab' ),
+				preventDefault: sinon.spy(),
+				stopPropagation: sinon.spy()
 			};
 
 			sinon.spy( editor, 'execute' );
@@ -143,10 +144,12 @@ describe( 'List', () => {
 
 			expect( editor.execute.calledOnce ).to.be.true;
 			expect( editor.execute.calledWithExactly( 'indentList' ) ).to.be.true;
+			sinon.assert.calledOnce( domEvtDataStub.preventDefault );
+			sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
 		} );
 
 		it( 'should execute outdentList command on Shift+Tab keystroke', () => {
-			domEvtDataStub.keystroke += getCode( 'Shift' );
+			domEvtDataStub.keyCode += getCode( 'Shift' );
 
 			setData(
 				doc,
@@ -158,6 +161,8 @@ describe( 'List', () => {
 
 			expect( editor.execute.calledOnce ).to.be.true;
 			expect( editor.execute.calledWithExactly( 'outdentList' ) ).to.be.true;
+			sinon.assert.calledOnce( domEvtDataStub.preventDefault );
+			sinon.assert.calledOnce( domEvtDataStub.stopPropagation );
 		} );
 
 		it( 'should not indent if command is disabled', () => {
@@ -166,10 +171,12 @@ describe( 'List', () => {
 			editor.editing.view.fire( 'keydown', domEvtDataStub );
 
 			expect( editor.execute.called ).to.be.false;
+			sinon.assert.notCalled( domEvtDataStub.preventDefault );
+			sinon.assert.notCalled( domEvtDataStub.stopPropagation );
 		} );
 
 		it( 'should not indent or outdent if alt+tab is pressed', () => {
-			domEvtDataStub.keystroke += getCode( 'alt' );
+			domEvtDataStub.keyCode += getCode( 'alt' );
 
 			setData(
 				doc,
@@ -180,6 +187,8 @@ describe( 'List', () => {
 			editor.editing.view.fire( 'keydown', domEvtDataStub );
 
 			expect( editor.execute.called ).to.be.false;
+			sinon.assert.notCalled( domEvtDataStub.preventDefault );
+			sinon.assert.notCalled( domEvtDataStub.stopPropagation );
 		} );
 	} );
 } );