| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
- import Enter from '../src/enter';
- import EnterCommand from '../src/entercommand';
- import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
- describe( 'Enter feature', () => {
- let editor, editingView;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Enter ]
- } )
- .then( newEditor => {
- editor = newEditor;
- editingView = editor.editing.view;
- } );
- } );
- it( 'creates the commands', () => {
- expect( editor.commands.get( 'enter' ) ).to.be.instanceof( EnterCommand );
- } );
- it( 'listens to the editing view enter event', () => {
- const spy = editor.execute = sinon.spy();
- const view = editor.editing.view;
- const domEvt = getDomEvent();
- view.fire( 'enter', new DomEventData( editingView, domEvt ) );
- expect( spy.calledOnce ).to.be.true;
- expect( spy.calledWithExactly( 'enter' ) ).to.be.true;
- expect( domEvt.preventDefault.calledOnce ).to.be.true;
- } );
- it( 'scrolls the editing document to the selection after executing the command', () => {
- const view = editor.editing.view;
- const domEvt = getDomEvent();
- const executeSpy = editor.execute = sinon.spy();
- const scrollSpy = sinon.stub( view, 'scrollToTheSelection' );
- view.fire( 'enter', new DomEventData( editingView, domEvt ) );
- sinon.assert.calledOnce( scrollSpy );
- sinon.assert.callOrder( executeSpy, scrollSpy );
- } );
- function getDomEvent() {
- return {
- preventDefault: sinon.spy()
- };
- }
- } );
|