|
|
@@ -13,8 +13,8 @@ var modules = bender.amd.require(
|
|
|
'document/attribute',
|
|
|
'document/nodelist' );
|
|
|
|
|
|
-describe( 'tree', function() {
|
|
|
- var Element, Character;
|
|
|
+describe( 'Node', function() {
|
|
|
+ var Element, Character, Attribute, NodeList;
|
|
|
|
|
|
var root;
|
|
|
var one, two, three;
|
|
|
@@ -23,6 +23,8 @@ describe( 'tree', function() {
|
|
|
before( function() {
|
|
|
Element = modules[ 'document/element' ];
|
|
|
Character = modules[ 'document/character' ];
|
|
|
+ Attribute = modules[ 'document/attribute' ];
|
|
|
+ NodeList = modules[ 'document/nodelist' ];
|
|
|
|
|
|
charB = new Character( 'b' );
|
|
|
charA = new Character( 'a' );
|
|
|
@@ -36,209 +38,181 @@ describe( 'tree', function() {
|
|
|
root = new Element( null, null, [ one, two, three ] );
|
|
|
} );
|
|
|
|
|
|
- it( 'should have proper positionInParent', function() {
|
|
|
- expect( root ).to.have.property( 'positionInParent' ).that.is.null;
|
|
|
+ describe( 'should have a correct property', function() {
|
|
|
+ it( 'positionInParent', function() {
|
|
|
+ expect( root ).to.have.property( 'positionInParent' ).that.is.null;
|
|
|
|
|
|
- expect( one ).to.have.property( 'positionInParent' ).that.equals( 0 );
|
|
|
- expect( two ).to.have.property( 'positionInParent' ).that.equals( 1 );
|
|
|
- expect( three ).to.have.property( 'positionInParent' ).that.equals( 2 );
|
|
|
+ expect( one ).to.have.property( 'positionInParent' ).that.equals( 0 );
|
|
|
+ expect( two ).to.have.property( 'positionInParent' ).that.equals( 1 );
|
|
|
+ expect( three ).to.have.property( 'positionInParent' ).that.equals( 2 );
|
|
|
|
|
|
- expect( charB ).to.have.property( 'positionInParent' ).that.equals( 0 );
|
|
|
- expect( charA ).to.have.property( 'positionInParent' ).that.equals( 1 );
|
|
|
- expect( img ).to.have.property( 'positionInParent' ).that.equals( 2 );
|
|
|
- expect( charR ).to.have.property( 'positionInParent' ).that.equals( 3 );
|
|
|
- } );
|
|
|
+ expect( charB ).to.have.property( 'positionInParent' ).that.equals( 0 );
|
|
|
+ expect( charA ).to.have.property( 'positionInParent' ).that.equals( 1 );
|
|
|
+ expect( img ).to.have.property( 'positionInParent' ).that.equals( 2 );
|
|
|
+ expect( charR ).to.have.property( 'positionInParent' ).that.equals( 3 );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should have proper depth', function() {
|
|
|
- expect( root ).to.have.property( 'depth' ).that.equals( 0 );
|
|
|
+ it( 'depth', function() {
|
|
|
+ expect( root ).to.have.property( 'depth' ).that.equals( 0 );
|
|
|
|
|
|
- expect( one ).to.have.property( 'depth' ).that.equals( 1 );
|
|
|
- expect( two ).to.have.property( 'depth' ).that.equals( 1 );
|
|
|
- expect( three ).to.have.property( 'depth' ).that.equals( 1 );
|
|
|
+ expect( one ).to.have.property( 'depth' ).that.equals( 1 );
|
|
|
+ expect( two ).to.have.property( 'depth' ).that.equals( 1 );
|
|
|
+ expect( three ).to.have.property( 'depth' ).that.equals( 1 );
|
|
|
|
|
|
- expect( charB ).to.have.property( 'depth' ).that.equals( 2 );
|
|
|
- expect( charA ).to.have.property( 'depth' ).that.equals( 2 );
|
|
|
- expect( img ).to.have.property( 'depth' ).that.equals( 2 );
|
|
|
- expect( charR ).to.have.property( 'depth' ).that.equals( 2 );
|
|
|
- } );
|
|
|
+ expect( charB ).to.have.property( 'depth' ).that.equals( 2 );
|
|
|
+ expect( charA ).to.have.property( 'depth' ).that.equals( 2 );
|
|
|
+ expect( img ).to.have.property( 'depth' ).that.equals( 2 );
|
|
|
+ expect( charR ).to.have.property( 'depth' ).that.equals( 2 );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should have proper root', function() {
|
|
|
- expect( root ).to.have.property( 'root' ).that.equals( root );
|
|
|
+ it( 'root', function() {
|
|
|
+ expect( root ).to.have.property( 'root' ).that.equals( root );
|
|
|
|
|
|
- expect( one ).to.have.property( 'root' ).that.equals( root );
|
|
|
- expect( two ).to.have.property( 'root' ).that.equals( root );
|
|
|
- expect( three ).to.have.property( 'root' ).that.equals( root );
|
|
|
+ expect( one ).to.have.property( 'root' ).that.equals( root );
|
|
|
+ expect( two ).to.have.property( 'root' ).that.equals( root );
|
|
|
+ expect( three ).to.have.property( 'root' ).that.equals( root );
|
|
|
|
|
|
- expect( charB ).to.have.property( 'root' ).that.equals( root );
|
|
|
- expect( charA ).to.have.property( 'root' ).that.equals( root );
|
|
|
- expect( img ).to.have.property( 'root' ).that.equals( root );
|
|
|
- expect( charR ).to.have.property( 'root' ).that.equals( root );
|
|
|
- } );
|
|
|
+ expect( charB ).to.have.property( 'root' ).that.equals( root );
|
|
|
+ expect( charA ).to.have.property( 'root' ).that.equals( root );
|
|
|
+ expect( img ).to.have.property( 'root' ).that.equals( root );
|
|
|
+ expect( charR ).to.have.property( 'root' ).that.equals( root );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should have proper nextSibling', function() {
|
|
|
- expect( root ).to.have.property( 'nextSibling' ).that.is.null;
|
|
|
+ it( 'nextSibling', function() {
|
|
|
+ expect( root ).to.have.property( 'nextSibling' ).that.is.null;
|
|
|
|
|
|
- expect( one ).to.have.property( 'nextSibling' ).that.equals( two );
|
|
|
- expect( two ).to.have.property( 'nextSibling' ).that.equals( three );
|
|
|
- expect( three ).to.have.property( 'nextSibling' ).that.is.null;
|
|
|
+ expect( one ).to.have.property( 'nextSibling' ).that.equals( two );
|
|
|
+ expect( two ).to.have.property( 'nextSibling' ).that.equals( three );
|
|
|
+ expect( three ).to.have.property( 'nextSibling' ).that.is.null;
|
|
|
|
|
|
- expect( charB ).to.have.property( 'nextSibling' ).that.equals( charA );
|
|
|
- expect( charA ).to.have.property( 'nextSibling' ).that.equals( img );
|
|
|
- expect( img ).to.have.property( 'nextSibling' ).that.equals( charR );
|
|
|
- expect( charR ).to.have.property( 'nextSibling' ).that.is.null;
|
|
|
- } );
|
|
|
+ expect( charB ).to.have.property( 'nextSibling' ).that.equals( charA );
|
|
|
+ expect( charA ).to.have.property( 'nextSibling' ).that.equals( img );
|
|
|
+ expect( img ).to.have.property( 'nextSibling' ).that.equals( charR );
|
|
|
+ expect( charR ).to.have.property( 'nextSibling' ).that.is.null;
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should have proper previousSibling', function() {
|
|
|
- expect( root ).to.have.property( 'previousSibling' ).that.is.expect;
|
|
|
+ it( 'previousSibling', function() {
|
|
|
+ expect( root ).to.have.property( 'previousSibling' ).that.is.expect;
|
|
|
|
|
|
- expect( one ).to.have.property( 'previousSibling' ).that.is.null;
|
|
|
- expect( two ).to.have.property( 'previousSibling' ).that.equals( one );
|
|
|
- expect( three ).to.have.property( 'previousSibling' ).that.equals( two );
|
|
|
+ expect( one ).to.have.property( 'previousSibling' ).that.is.null;
|
|
|
+ expect( two ).to.have.property( 'previousSibling' ).that.equals( one );
|
|
|
+ expect( three ).to.have.property( 'previousSibling' ).that.equals( two );
|
|
|
|
|
|
- expect( charB ).to.have.property( 'previousSibling' ).that.is.null;
|
|
|
- expect( charA ).to.have.property( 'previousSibling' ).that.equals( charB );
|
|
|
- expect( img ).to.have.property( 'previousSibling' ).that.equals( charA );
|
|
|
- expect( charR ).to.have.property( 'previousSibling' ).that.equals( img );
|
|
|
+ expect( charB ).to.have.property( 'previousSibling' ).that.is.null;
|
|
|
+ expect( charA ).to.have.property( 'previousSibling' ).that.equals( charB );
|
|
|
+ expect( img ).to.have.property( 'previousSibling' ).that.equals( charA );
|
|
|
+ expect( charR ).to.have.property( 'previousSibling' ).that.equals( img );
|
|
|
+ } );
|
|
|
} );
|
|
|
-} );
|
|
|
-
|
|
|
-describe( 'constructor', function() {
|
|
|
- it( 'should copy attributes, not pass by reference', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
|
|
|
- var attrs = [ new Attribute( 'attr', true ) ];
|
|
|
- var foo = new Element( 'foo', attrs );
|
|
|
- var bar = new Element( 'bar', attrs );
|
|
|
+ describe( 'constructor', function() {
|
|
|
+ it( 'should copy attributes, not pass by reference', function() {
|
|
|
+ var attrs = [ new Attribute( 'attr', true ) ];
|
|
|
+ var foo = new Element( 'foo', attrs );
|
|
|
+ var bar = new Element( 'bar', attrs );
|
|
|
|
|
|
- foo.removeAttr( 'attr' );
|
|
|
+ foo.removeAttr( 'attr' );
|
|
|
|
|
|
- expect( foo._getAttrCount() ).to.equal( 0 );
|
|
|
- expect( bar._getAttrCount() ).to.equal( 1 );
|
|
|
+ expect( foo._getAttrCount() ).to.equal( 0 );
|
|
|
+ expect( bar._getAttrCount() ).to.equal( 1 );
|
|
|
+ } );
|
|
|
} );
|
|
|
-} );
|
|
|
-
|
|
|
-describe( 'getAttr', function() {
|
|
|
- it( 'should be possible to get attribute by key', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
|
|
|
- var fooAttr = new Attribute( 'foo', true );
|
|
|
- var element = new Element( 'foo', [ fooAttr ] );
|
|
|
+ describe( 'getAttr', function() {
|
|
|
+ var fooAttr, element;
|
|
|
|
|
|
- expect( element.getAttr( 'foo' ) ).to.equal( fooAttr.value );
|
|
|
- } );
|
|
|
+ beforeEach( function() {
|
|
|
+ fooAttr = new Attribute( 'foo', true );
|
|
|
+ element = new Element( 'foo', [ fooAttr ] );
|
|
|
+ } );
|
|
|
|
|
|
- it( 'should return null if attribute was not found by key', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
+ it( 'should be possible to get attribute by key', function() {
|
|
|
+ expect( element.getAttr( 'foo' ) ).to.equal( fooAttr.value );
|
|
|
+ } );
|
|
|
|
|
|
- var fooAttr = new Attribute( 'foo', true );
|
|
|
- var element = new Element( 'foo', [ fooAttr ] );
|
|
|
-
|
|
|
- expect( element.getAttr( 'bar' ) ).to.be.null;
|
|
|
+ it( 'should return null if attribute was not found by key', function() {
|
|
|
+ expect( element.getAttr( 'bar' ) ).to.be.null;
|
|
|
+ } );
|
|
|
} );
|
|
|
-} );
|
|
|
|
|
|
-describe( 'setAttr', function() {
|
|
|
- it( 'should insert an attribute', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
+ describe( 'setAttr', function() {
|
|
|
+ it( 'should insert an attribute', function() {
|
|
|
+ var element = new Element( 'elem' );
|
|
|
+ var attr = new Attribute( 'foo', 'bar' );
|
|
|
|
|
|
- var element = new Element( 'elem' );
|
|
|
- var attr = new Attribute( 'foo', 'bar' );
|
|
|
- element.setAttr( attr );
|
|
|
+ element.setAttr( attr );
|
|
|
|
|
|
- expect( element._getAttrCount() ).to.equal( 1 );
|
|
|
- expect( element.getAttr( attr.key ) ).to.equal( attr.value );
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should overwrite attribute with the same key', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
-
|
|
|
- var oldAttr = new Attribute( 'foo', 'bar' );
|
|
|
- var newAttr = new Attribute( 'foo', 'bar' );
|
|
|
- var element = new Element( 'elem', [ oldAttr ] );
|
|
|
+ expect( element._getAttrCount() ).to.equal( 1 );
|
|
|
+ expect( element.getAttr( attr.key ) ).to.equal( attr.value );
|
|
|
+ } );
|
|
|
|
|
|
- element.setAttr( newAttr );
|
|
|
+ it( 'should overwrite attribute with the same key', function() {
|
|
|
+ var oldAttr = new Attribute( 'foo', 'bar' );
|
|
|
+ var newAttr = new Attribute( 'foo', 'bar' );
|
|
|
+ var element = new Element( 'elem', [ oldAttr ] );
|
|
|
|
|
|
- expect( element._getAttrCount() ).to.equal( 1 );
|
|
|
- expect( element.getAttr( newAttr.key ) ).to.equal( newAttr.value );
|
|
|
- } );
|
|
|
-} );
|
|
|
+ element.setAttr( newAttr );
|
|
|
|
|
|
-describe( 'removeAttr', function() {
|
|
|
- it( 'should remove an attribute', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
-
|
|
|
- var attrA = new Attribute( 'a', 'A' );
|
|
|
- var attrB = new Attribute( 'b', 'b' );
|
|
|
- var attrC = new Attribute( 'c', 'C' );
|
|
|
- var element = new Element( 'elem', [ attrA, attrB, attrC ] );
|
|
|
- element.removeAttr( attrB.key );
|
|
|
-
|
|
|
- expect( element._getAttrCount() ).to.equal( 2 );
|
|
|
- expect( element.getAttr( attrA.key ) ).to.equal( attrA.value );
|
|
|
- expect( element.getAttr( attrC.key ) ).to.equal( attrC.value );
|
|
|
- expect( element.getAttr( attrB.key ) ).to.be.null;
|
|
|
+ expect( element._getAttrCount() ).to.equal( 1 );
|
|
|
+ expect( element.getAttr( newAttr.key ) ).to.equal( newAttr.value );
|
|
|
+ } );
|
|
|
} );
|
|
|
-} );
|
|
|
|
|
|
-describe( 'hasAttr', function() {
|
|
|
- it( 'should check attribute by key', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
+ describe( 'removeAttr', function() {
|
|
|
+ it( 'should remove an attribute', function() {
|
|
|
+ var attrA = new Attribute( 'a', 'A' );
|
|
|
+ var attrB = new Attribute( 'b', 'b' );
|
|
|
+ var attrC = new Attribute( 'c', 'C' );
|
|
|
+ var element = new Element( 'elem', [ attrA, attrB, attrC ] );
|
|
|
|
|
|
- var fooAttr = new Attribute( 'foo', true );
|
|
|
- var element = new Element( 'foo', [ fooAttr ] );
|
|
|
+ element.removeAttr( attrB.key );
|
|
|
|
|
|
- expect( element.hasAttr( 'foo' ) ).to.be.true;
|
|
|
+ expect( element._getAttrCount() ).to.equal( 2 );
|
|
|
+ expect( element.getAttr( attrA.key ) ).to.equal( attrA.value );
|
|
|
+ expect( element.getAttr( attrC.key ) ).to.equal( attrC.value );
|
|
|
+ expect( element.getAttr( attrB.key ) ).to.be.null;
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
- it( 'should return false if attribute was not found by key', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
+ describe( 'hasAttr', function() {
|
|
|
+ it( 'should check attribute by key', function() {
|
|
|
+ var fooAttr = new Attribute( 'foo', true );
|
|
|
+ var element = new Element( 'foo', [ fooAttr ] );
|
|
|
|
|
|
- var fooAttr = new Attribute( 'foo', true );
|
|
|
- var element = new Element( 'foo', [ fooAttr ] );
|
|
|
+ expect( element.hasAttr( 'foo' ) ).to.be.true;
|
|
|
+ } );
|
|
|
|
|
|
- expect( element.hasAttr( 'bar' ) ).to.be.false;
|
|
|
- } );
|
|
|
-
|
|
|
- it( 'should check attribute by object', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
+ it( 'should return false if attribute was not found by key', function() {
|
|
|
+ var fooAttr = new Attribute( 'foo', true );
|
|
|
+ var element = new Element( 'foo', [ fooAttr ] );
|
|
|
|
|
|
- var fooAttr = new Attribute( 'foo', true );
|
|
|
- var foo2Attr = new Attribute( 'foo', true );
|
|
|
- var element = new Element( 'foo', [ fooAttr ] );
|
|
|
+ expect( element.hasAttr( 'bar' ) ).to.be.false;
|
|
|
+ } );
|
|
|
|
|
|
- expect( element.hasAttr( foo2Attr ) ).to.be.true;
|
|
|
- } );
|
|
|
+ it( 'should check attribute by object', function() {
|
|
|
+ var fooAttr = new Attribute( 'foo', true );
|
|
|
+ var foo2Attr = new Attribute( 'foo', true );
|
|
|
+ var element = new Element( 'foo', [ fooAttr ] );
|
|
|
|
|
|
- it( 'should return false if attribute was not found by object', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Attribute = modules[ 'document/attribute' ];
|
|
|
+ expect( element.hasAttr( foo2Attr ) ).to.be.true;
|
|
|
+ } );
|
|
|
|
|
|
- var fooAttr = new Attribute( 'foo', true );
|
|
|
- var element = new Element( 'foo' );
|
|
|
-
|
|
|
- expect( element.hasAttr( fooAttr ) ).to.be.false;
|
|
|
- } );
|
|
|
+ it( 'should return false if attribute was not found by object', function() {
|
|
|
+ var fooAttr = new Attribute( 'foo', true );
|
|
|
+ var element = new Element( 'foo' );
|
|
|
|
|
|
- it( 'should create proper JSON string using toJSON method', function() {
|
|
|
- var Element = modules[ 'document/element' ];
|
|
|
- var Character = modules[ 'document/character' ];
|
|
|
+ expect( element.hasAttr( fooAttr ) ).to.be.false;
|
|
|
+ } );
|
|
|
|
|
|
- var b = new Character( 'b' );
|
|
|
- var foo = new Element( 'foo', [], [ b ] );
|
|
|
+ it( 'should create proper JSON string using toJSON method', function() {
|
|
|
+ var b = new Character( 'b' );
|
|
|
+ var foo = new Element( 'foo', [], [ b ] );
|
|
|
|
|
|
- var parsedFoo = JSON.parse( JSON.stringify( foo ) );
|
|
|
- var parsedBar = JSON.parse( JSON.stringify( b ) );
|
|
|
+ var parsedFoo = JSON.parse( JSON.stringify( foo ) );
|
|
|
+ var parsedBar = JSON.parse( JSON.stringify( b ) );
|
|
|
|
|
|
- expect( parsedFoo.parent ).to.equal( null );
|
|
|
- expect( parsedBar.parent ).to.equal( 'foo' );
|
|
|
+ expect( parsedFoo.parent ).to.equal( null );
|
|
|
+ expect( parsedBar.parent ).to.equal( 'foo' );
|
|
|
+ } );
|
|
|
} );
|
|
|
} );
|