getpositionedancestor.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import getPositionedAncestor from 'ckeditor5/utils/dom/getpositionedancestor.js';
  7. describe( 'getPositionedAncestor', () => {
  8. let element;
  9. beforeEach( () => {
  10. element = document.createElement( 'a' );
  11. document.body.appendChild( element );
  12. } );
  13. it( 'should return null when there is no element', () => {
  14. expect( getPositionedAncestor() ).to.be.null;
  15. } );
  16. it( 'should return null when there is no parent', () => {
  17. expect( getPositionedAncestor( element ) ).to.be.null;
  18. } );
  19. it( 'should consider passed element', () => {
  20. element.style.position = 'relative';
  21. expect( getPositionedAncestor( element ) ).to.equal( element );
  22. } );
  23. it( 'should find the positioned ancestor (direct parent)', () => {
  24. const parent = document.createElement( 'div' );
  25. parent.appendChild( element );
  26. document.body.appendChild( parent );
  27. parent.style.position = 'absolute';
  28. expect( getPositionedAncestor( element ) ).to.equal( parent );
  29. } );
  30. it( 'should find the positioned ancestor (far ancestor)', () => {
  31. const parentA = document.createElement( 'div' );
  32. const parentB = document.createElement( 'div' );
  33. parentB.appendChild( element );
  34. parentA.appendChild( parentB );
  35. document.body.appendChild( parentA );
  36. parentA.style.position = 'absolute';
  37. expect( getPositionedAncestor( element ) ).to.equal( parentA );
  38. } );
  39. } );