enter.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import Editor from '/ckeditor5/editor.js';
  7. import StandardCreator from '/ckeditor5/creator/standardcreator.js';
  8. import Enter from '/ckeditor5/enter/enter.js';
  9. import EnterCommand from '/ckeditor5/enter/entercommand.js';
  10. import DomEventData from '/ckeditor5/engine/view/observer/domeventdata.js';
  11. describe( 'Enter feature', () => {
  12. let editor, editingView;
  13. beforeEach( () => {
  14. editor = new Editor( null, {
  15. creator: StandardCreator,
  16. features: [ Enter ]
  17. } );
  18. return editor.init()
  19. .then( () => {
  20. editor.document.createRoot( 'main' );
  21. editingView = editor.editing.view;
  22. } );
  23. } );
  24. it( 'creates the commands', () => {
  25. expect( editor.commands.get( 'enter' ) ).to.be.instanceof( EnterCommand );
  26. } );
  27. it( 'listens to the editing view enter event', () => {
  28. const spy = editor.execute = sinon.spy();
  29. const view = editor.editing.view;
  30. const domEvt = getDomEvent();
  31. view.fire( 'enter', new DomEventData( editingView, domEvt ) );
  32. expect( spy.calledOnce ).to.be.true;
  33. expect( spy.calledWithExactly( 'enter' ) ).to.be.true;
  34. expect( domEvt.preventDefault.calledOnce ).to.be.true;
  35. } );
  36. function getDomEvent() {
  37. return {
  38. preventDefault: sinon.spy()
  39. };
  40. }
  41. } );