8
0

submithandler.js 1014 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global document, Event */
  6. import submitHandler from '../../src/bindings/submithandler';
  7. import View from '../../src/view';
  8. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  9. describe( 'submitHandler', () => {
  10. let view;
  11. testUtils.createSinonSandbox();
  12. beforeEach( () => {
  13. view = new View();
  14. view.element = document.createElement( 'div' );
  15. view.element.child = document.createElement( 'input' );
  16. view.element.appendChild( view.element.child );
  17. submitHandler( { view } );
  18. } );
  19. it( 'should fire #submit event on the view and prevent the native DOM #submit', done => {
  20. const evt = new Event( 'submit' );
  21. const spy = sinon.spy( evt, 'preventDefault' );
  22. view.on( 'submit', () => {
  23. sinon.assert.calledOnce( spy );
  24. done();
  25. } );
  26. view.element.child.dispatchEvent( evt );
  27. } );
  28. } );