node.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 depth', function() {
  35. expect( root ).to.have.property( 'depth' ).that.equals( 0 );
  36. expect( one ).to.have.property( 'depth' ).that.equals( 1 );
  37. expect( two ).to.have.property( 'depth' ).that.equals( 1 );
  38. expect( three ).to.have.property( 'depth' ).that.equals( 1 );
  39. expect( charB ).to.have.property( 'depth' ).that.equals( 2 );
  40. expect( charA ).to.have.property( 'depth' ).that.equals( 2 );
  41. expect( img ).to.have.property( 'depth' ).that.equals( 2 );
  42. expect( charR ).to.have.property( 'depth' ).that.equals( 2 );
  43. } );
  44. it( 'should have proper nextSibling', function() {
  45. expect( root ).to.have.property( 'nextSibling' ).that.is.null;
  46. expect( one ).to.have.property( 'nextSibling' ).that.equals( two );
  47. expect( two ).to.have.property( 'nextSibling' ).that.equals( three );
  48. expect( three ).to.have.property( 'nextSibling' ).that.is.null;
  49. expect( charB ).to.have.property( 'nextSibling' ).that.equals( charA );
  50. expect( charA ).to.have.property( 'nextSibling' ).that.equals( img );
  51. expect( img ).to.have.property( 'nextSibling' ).that.equals( charR );
  52. expect( charR ).to.have.property( 'nextSibling' ).that.is.null;
  53. } );
  54. it( 'should have proper previousSibling', function() {
  55. expect( root ).to.have.property( 'previousSibling' ).that.is.expect;
  56. expect( one ).to.have.property( 'previousSibling' ).that.is.null;
  57. expect( two ).to.have.property( 'previousSibling' ).that.equals( one );
  58. expect( three ).to.have.property( 'previousSibling' ).that.equals( two );
  59. expect( charB ).to.have.property( 'previousSibling' ).that.is.null;
  60. expect( charA ).to.have.property( 'previousSibling' ).that.equals( charB );
  61. expect( img ).to.have.property( 'previousSibling' ).that.equals( charA );
  62. expect( charR ).to.have.property( 'previousSibling' ).that.equals( img );
  63. } );
  64. } );