focusobserver.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. treeView.addObserver( FocusObserver );
  14. observer = treeView.getObserver( FocusObserver );
  15. } );
  16. it( 'should define domEventType', () => {
  17. expect( observer.domEventType ).to.deep.equal( [ 'focus', 'blur' ] );
  18. } );
  19. describe( 'onDomEvent', () => {
  20. it( 'should fire focus with the right event data', () => {
  21. const spy = sinon.spy();
  22. treeView.on( 'focus', spy );
  23. observer.onDomEvent( { type: 'focus', target: document.body } );
  24. expect( spy.calledOnce ).to.be.true;
  25. const data = spy.args[ 0 ][ 1 ];
  26. expect( data.domTarget ).to.equal( document.body );
  27. } );
  28. it( 'should fire blur with the right event data', () => {
  29. const spy = sinon.spy();
  30. treeView.on( 'blur', spy );
  31. observer.onDomEvent( { type: 'blur', target: document.body } );
  32. expect( spy.calledOnce ).to.be.true;
  33. const data = spy.args[ 0 ][ 1 ];
  34. expect( data.domTarget ).to.equal( document.body );
  35. } );
  36. } );
  37. } );