focusobserver.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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, viewBody, observer;
  11. beforeEach( () => {
  12. treeView = new TreeView();
  13. treeView.addObserver( FocusObserver );
  14. viewBody = treeView.domConverter.domToView( document.body, { bind: true } );
  15. observer = Array.from( treeView._observers )[ 0 ];
  16. } );
  17. it( 'should define domEventType', () => {
  18. expect( observer.domEventType ).to.deep.equal( [ 'focus', 'blur' ] );
  19. } );
  20. describe( 'onDomEvent', () => {
  21. it( 'should fire focus with the target', () => {
  22. const spy = sinon.spy();
  23. treeView.on( 'focus', spy );
  24. observer.onDomEvent( { type: 'focus', target: document.body } );
  25. expect( spy.calledOnce ).to.be.true;
  26. const data = spy.args[ 0 ][ 1 ];
  27. expect( data.viewTarget ).to.equal( viewBody );
  28. expect( data.domTarget ).to.equal( document.body );
  29. } );
  30. it( 'should fire blur with the target', () => {
  31. const spy = sinon.spy();
  32. treeView.on( 'blur', spy );
  33. observer.onDomEvent( { type: 'blur', target: document.body } );
  34. expect( spy.calledOnce ).to.be.true;
  35. const data = spy.args[ 0 ][ 1 ];
  36. expect( data.viewTarget ).to.equal( viewBody );
  37. expect( data.domTarget ).to.equal( document.body );
  38. } );
  39. } );
  40. } );