enter.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 VirtualTestEditor from '/tests/ckeditor5/_utils/virtualtesteditor.js';
  7. import Enter from '/ckeditor5/enter/enter.js';
  8. import EnterCommand from '/ckeditor5/enter/entercommand.js';
  9. import DomEventData from '/ckeditor5/engine/view/observer/domeventdata.js';
  10. describe( 'Enter feature', () => {
  11. let editor, editingView;
  12. beforeEach( () => {
  13. return VirtualTestEditor.create( {
  14. features: [ 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. function getDomEvent() {
  34. return {
  35. preventDefault: sinon.spy()
  36. };
  37. }
  38. } );