8
0

utils.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import ViewAttributeElement from '../../src/view/attributeelement';
  6. import ViewContainerElement from '../../src/view/containerelement';
  7. import ViewText from '../../src/view/text';
  8. import { getTouchingTextNode } from '../../src/view/utils';
  9. describe( 'getTouchingTextNode()', () => {
  10. let a, b, x, y;
  11. beforeEach( () => {
  12. a = new ViewText( 'a' );
  13. b = new ViewText( 'b' );
  14. x = new ViewText( 'x' );
  15. y = new ViewText( 'y' );
  16. // <div><p>ab</p><p><em><strong>x</strong></em>y</p></div>
  17. /* eslint-disable no-new */
  18. new ViewContainerElement( 'div', null, [
  19. new ViewContainerElement( 'p', null, [ a, b ] ),
  20. new ViewContainerElement( 'p', null, [
  21. new ViewAttributeElement( 'em', null, new ViewAttributeElement( 'strong', null, x ) ),
  22. y
  23. ] )
  24. ] );
  25. } );
  26. it( 'should return next touching view text node', () => {
  27. expect( getTouchingTextNode( a, true ) ).to.equal( b );
  28. } );
  29. it( 'should return previous touching view text node', () => {
  30. expect( getTouchingTextNode( b, false ) ).to.equal( a );
  31. } );
  32. it( 'should go outside of attribute element looking for text nodes', () => {
  33. expect( getTouchingTextNode( x, true ) ).to.equal( y );
  34. } );
  35. it( 'should go inside attribute element looking for text nodes', () => {
  36. expect( getTouchingTextNode( y, false ) ).to.equal( x );
  37. } );
  38. it( 'should return null if there is no next text node in given container element', () => {
  39. expect( getTouchingTextNode( b, true ) ).to.be.null;
  40. expect( getTouchingTextNode( y, true ) ).to.be.null;
  41. } );
  42. it( 'should return null if there is no previous text node in given container element', () => {
  43. expect( getTouchingTextNode( a, false ) ).to.be.null;
  44. expect( getTouchingTextNode( x, false ) ).to.be.null;
  45. } );
  46. } );