focusobserver.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treeview */
  6. 'use strict';
  7. import FocusObserver from '/ckeditor5/engine/treeview/observer/focusobserver.js';
  8. import TreeView from '/ckeditor5/engine/treeview/treeview.js';
  9. describe( 'FocusObserver', () => {
  10. let treeView, observer;
  11. beforeEach( () => {
  12. treeView = new TreeView();
  13. observer = treeView.addObserver( FocusObserver );
  14. } );
  15. it( 'should define domEventType', () => {
  16. expect( observer.domEventType ).to.deep.equal( [ 'focus', 'blur' ] );
  17. } );
  18. describe( 'onDomEvent', () => {
  19. it( 'should fire focus with the right event data', () => {
  20. const spy = sinon.spy();
  21. treeView.on( 'focus', spy );
  22. observer.onDomEvent( { type: 'focus', target: document.body } );
  23. expect( spy.calledOnce ).to.be.true;
  24. const data = spy.args[ 0 ][ 1 ];
  25. expect( data.domTarget ).to.equal( document.body );
  26. } );
  27. it( 'should fire blur with the right event data', () => {
  28. const spy = sinon.spy();
  29. treeView.on( 'blur', spy );
  30. observer.onDomEvent( { type: 'blur', target: document.body } );
  31. expect( spy.calledOnce ).to.be.true;
  32. const data = spy.args[ 0 ][ 1 ];
  33. expect( data.domTarget ).to.equal( document.body );
  34. } );
  35. } );
  36. } );