8
0

node.js 2.8 KB

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