focusobserver.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/core/treeview/observer/focusobserver.js';
  8. import TreeView from '/ckeditor5/core/treeview/treeview.js';
  9. describe( 'FocusObserver', () => {
  10. let treeView, observer;
  11. beforeEach( () => {
  12. treeView = new TreeView();
  13. treeView.addObserver( FocusObserver );
  14. observer = Array.from( treeView._observers )[ 0 ];
  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 target', () => {
  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. expect( spy.calledWith( document.body ) );
  26. } );
  27. it( 'should fire blur with the target', () => {
  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. expect( spy.calledWith( document.body ) );
  33. } );
  34. } );
  35. } );