enter.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  6. import Enter from '../src/enter';
  7. import EnterCommand from '../src/entercommand';
  8. import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata';
  9. describe( 'Enter feature', () => {
  10. let editor, editingView;
  11. beforeEach( () => {
  12. return VirtualTestEditor
  13. .create( {
  14. plugins: [ Enter ]
  15. } )
  16. .then( newEditor => {
  17. editor = newEditor;
  18. editingView = editor.editing.view;
  19. } );
  20. } );
  21. it( 'creates the commands', () => {
  22. expect( editor.commands.get( 'enter' ) ).to.be.instanceof( EnterCommand );
  23. } );
  24. it( 'listens to the editing view enter event', () => {
  25. const spy = editor.execute = sinon.spy();
  26. const view = editor.editing.view;
  27. const domEvt = getDomEvent();
  28. view.fire( 'enter', new DomEventData( editingView, domEvt ) );
  29. expect( spy.calledOnce ).to.be.true;
  30. expect( spy.calledWithExactly( 'enter' ) ).to.be.true;
  31. expect( domEvt.preventDefault.calledOnce ).to.be.true;
  32. } );
  33. it( 'scrolls the editing document to the selection after executing the command', () => {
  34. const view = editor.editing.view;
  35. const domEvt = getDomEvent();
  36. const executeSpy = editor.execute = sinon.spy();
  37. const scrollSpy = sinon.stub( view, 'scrollToTheSelection' );
  38. view.fire( 'enter', new DomEventData( editingView, domEvt ) );
  39. sinon.assert.calledOnce( scrollSpy );
  40. sinon.assert.callOrder( executeSpy, scrollSpy );
  41. } );
  42. function getDomEvent() {
  43. return {
  44. preventDefault: sinon.spy()
  45. };
  46. }
  47. } );