node.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: document */
  6. 'use strict';
  7. var modules = bender.amd.require(
  8. 'document/element',
  9. 'document/character' );
  10. describe( 'tree', function() {
  11. var Element, Character;
  12. var root;
  13. var one, two, three;
  14. var charB, charA, charR, img;
  15. before( function() {
  16. Element = modules[ 'document/element' ];
  17. Character = modules[ 'document/character' ];
  18. root = new Element();
  19. one = new Element( root );
  20. two = new Element( root );
  21. three = new Element( root );
  22. charB = new Character( two, 'b' );
  23. charA = new Character( two, 'a' );
  24. img = new Element( two, 'img' );
  25. charR = new Character( two, 'r' );
  26. two.children.push( charB );
  27. two.children.push( charA );
  28. two.children.push( img );
  29. two.children.push( charR );
  30. root.children.push( one );
  31. root.children.push( two );
  32. root.children.push( three );
  33. } );
  34. it( 'should have proper positionInParent', function() {
  35. expect( root ).to.have.property( 'positionInParent' ).that.is.null;
  36. expect( one ).to.have.property( 'positionInParent' ).that.equals( 0 );
  37. expect( two ).to.have.property( 'positionInParent' ).that.equals( 1 );
  38. expect( three ).to.have.property( 'positionInParent' ).that.equals( 2 );
  39. expect( charB ).to.have.property( 'positionInParent' ).that.equals( 0 );
  40. expect( charA ).to.have.property( 'positionInParent' ).that.equals( 1 );
  41. expect( img ).to.have.property( 'positionInParent' ).that.equals( 2 );
  42. expect( charR ).to.have.property( 'positionInParent' ).that.equals( 3 );
  43. } );
  44. it( 'should have proper depth', function() {
  45. expect( root ).to.have.property( 'depth' ).that.equals( 0 );
  46. expect( one ).to.have.property( 'depth' ).that.equals( 1 );
  47. expect( two ).to.have.property( 'depth' ).that.equals( 1 );
  48. expect( three ).to.have.property( 'depth' ).that.equals( 1 );
  49. expect( charB ).to.have.property( 'depth' ).that.equals( 2 );
  50. expect( charA ).to.have.property( 'depth' ).that.equals( 2 );
  51. expect( img ).to.have.property( 'depth' ).that.equals( 2 );
  52. expect( charR ).to.have.property( 'depth' ).that.equals( 2 );
  53. } );
  54. it( 'should have proper nextSibling', function() {
  55. expect( root ).to.have.property( 'nextSibling' ).that.is.null;
  56. expect( one ).to.have.property( 'nextSibling' ).that.equals( two );
  57. expect( two ).to.have.property( 'nextSibling' ).that.equals( three );
  58. expect( three ).to.have.property( 'nextSibling' ).that.is.null;
  59. expect( charB ).to.have.property( 'nextSibling' ).that.equals( charA );
  60. expect( charA ).to.have.property( 'nextSibling' ).that.equals( img );
  61. expect( img ).to.have.property( 'nextSibling' ).that.equals( charR );
  62. expect( charR ).to.have.property( 'nextSibling' ).that.is.null;
  63. } );
  64. it( 'should have proper previousSibling', function() {
  65. expect( root ).to.have.property( 'previousSibling' ).that.is.expect;
  66. expect( one ).to.have.property( 'previousSibling' ).that.is.null;
  67. expect( two ).to.have.property( 'previousSibling' ).that.equals( one );
  68. expect( three ).to.have.property( 'previousSibling' ).that.equals( two );
  69. expect( charB ).to.have.property( 'previousSibling' ).that.is.null;
  70. expect( charA ).to.have.property( 'previousSibling' ).that.equals( charB );
  71. expect( img ).to.have.property( 'previousSibling' ).that.equals( charA );
  72. expect( charR ).to.have.property( 'previousSibling' ).that.equals( img );
  73. } );
  74. } );