|
|
@@ -16,31 +16,31 @@ const getIteratorCount = coreTestUtils.getIteratorCount;
|
|
|
describe( 'Element', () => {
|
|
|
describe( 'constructor', () => {
|
|
|
it( 'should create element without attributes', () => {
|
|
|
- const elem = new ViewElement( 'p' );
|
|
|
+ const el = new ViewElement( 'p' );
|
|
|
|
|
|
- expect( elem ).to.be.an.instanceof( Node );
|
|
|
- expect( elem ).to.have.property( 'name' ).that.equals( 'p' );
|
|
|
- expect( elem ).to.have.property( 'parent' ).that.is.null;
|
|
|
- expect( getIteratorCount( elem.getAttrKeys() ) ).to.equal( 0 );
|
|
|
+ expect( el ).to.be.an.instanceof( Node );
|
|
|
+ expect( el ).to.have.property( 'name' ).that.equals( 'p' );
|
|
|
+ expect( el ).to.have.property( 'parent' ).that.is.null;
|
|
|
+ expect( getIteratorCount( el.getAttrKeys() ) ).to.equal( 0 );
|
|
|
} );
|
|
|
|
|
|
it( 'should create element with attributes as plain object', () => {
|
|
|
- const elem = new ViewElement( 'p', { 'foo': 'bar' } );
|
|
|
+ const el = new ViewElement( 'p', { 'foo': 'bar' } );
|
|
|
|
|
|
- expect( elem ).to.have.property( 'name' ).that.equals( 'p' );
|
|
|
- expect( getIteratorCount( elem.getAttrKeys() ) ).to.equal( 1 );
|
|
|
- expect( elem.getAttr( 'foo' ) ).to.equal( 'bar' );
|
|
|
+ expect( el ).to.have.property( 'name' ).that.equals( 'p' );
|
|
|
+ expect( getIteratorCount( el.getAttrKeys() ) ).to.equal( 1 );
|
|
|
+ expect( el.getAttr( 'foo' ) ).to.equal( 'bar' );
|
|
|
} );
|
|
|
|
|
|
it( 'should create element with attributes as map', () => {
|
|
|
const attrs = new Map();
|
|
|
attrs.set( 'foo', 'bar' );
|
|
|
|
|
|
- const elem = new ViewElement( 'p', attrs );
|
|
|
+ const el = new ViewElement( 'p', attrs );
|
|
|
|
|
|
- expect( elem ).to.have.property( 'name' ).that.equals( 'p' );
|
|
|
- expect( getIteratorCount( elem.getAttrKeys() ) ).to.equal( 1 );
|
|
|
- expect( elem.getAttr( 'foo' ) ).to.equal( 'bar' );
|
|
|
+ expect( el ).to.have.property( 'name' ).that.equals( 'p' );
|
|
|
+ expect( getIteratorCount( el.getAttrKeys() ) ).to.equal( 1 );
|
|
|
+ expect( el.getAttr( 'foo' ) ).to.equal( 'bar' );
|
|
|
} );
|
|
|
|
|
|
it( 'should create element with children', () => {
|
|
|
@@ -54,59 +54,59 @@ describe( 'Element', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'children manipulation methods', () => {
|
|
|
- let parent, e1, e2, e3, e4;
|
|
|
+ let parent, el1, el2, el3, el4;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
parent = new ViewElement( 'p' );
|
|
|
- e1 = new ViewElement( 'e1' );
|
|
|
- e2 = new ViewElement( 'e2' );
|
|
|
- e3 = new ViewElement( 'e3' );
|
|
|
- e4 = new ViewElement( 'e4' );
|
|
|
+ el1 = new ViewElement( 'el1' );
|
|
|
+ el2 = new ViewElement( 'el2' );
|
|
|
+ el3 = new ViewElement( 'el3' );
|
|
|
+ el4 = new ViewElement( 'el4' );
|
|
|
} );
|
|
|
|
|
|
describe( 'insertion', () => {
|
|
|
it( 'should insert children', () => {
|
|
|
- parent.insertChildren( 0, [ e1, e3 ] );
|
|
|
- parent.insertChildren( 1, e2 );
|
|
|
+ parent.insertChildren( 0, [ el1, el3 ] );
|
|
|
+ parent.insertChildren( 1, el2 );
|
|
|
|
|
|
expect( parent.getChildCount() ).to.equal( 3 );
|
|
|
- expect( parent.getChild( 0 ) ).to.have.property( 'name' ).that.equals( 'e1' );
|
|
|
- expect( parent.getChild( 1 ) ).to.have.property( 'name' ).that.equals( 'e2' );
|
|
|
- expect( parent.getChild( 2 ) ).to.have.property( 'name' ).that.equals( 'e3' );
|
|
|
+ expect( parent.getChild( 0 ) ).to.have.property( 'name' ).that.equals( 'el1' );
|
|
|
+ expect( parent.getChild( 1 ) ).to.have.property( 'name' ).that.equals( 'el2' );
|
|
|
+ expect( parent.getChild( 2 ) ).to.have.property( 'name' ).that.equals( 'el3' );
|
|
|
} );
|
|
|
|
|
|
it( 'should append children', () => {
|
|
|
- parent.insertChildren( 0, e1 );
|
|
|
- parent.appendChildren( e2 );
|
|
|
- parent.appendChildren( e3 );
|
|
|
+ parent.insertChildren( 0, el1 );
|
|
|
+ parent.appendChildren( el2 );
|
|
|
+ parent.appendChildren( el3 );
|
|
|
|
|
|
expect( parent.getChildCount() ).to.equal( 3 );
|
|
|
- expect( parent.getChild( 0 ) ).to.have.property( 'name' ).that.equals( 'e1' );
|
|
|
- expect( parent.getChild( 1 ) ).to.have.property( 'name' ).that.equals( 'e2' );
|
|
|
- expect( parent.getChild( 2 ) ).to.have.property( 'name' ).that.equals( 'e3' );
|
|
|
+ expect( parent.getChild( 0 ) ).to.have.property( 'name' ).that.equals( 'el1' );
|
|
|
+ expect( parent.getChild( 1 ) ).to.have.property( 'name' ).that.equals( 'el2' );
|
|
|
+ expect( parent.getChild( 2 ) ).to.have.property( 'name' ).that.equals( 'el3' );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'getChildIndex', () => {
|
|
|
it( 'should return child index', () => {
|
|
|
- parent.appendChildren( e1 );
|
|
|
- parent.appendChildren( e2 );
|
|
|
- parent.appendChildren( e3 );
|
|
|
+ parent.appendChildren( el1 );
|
|
|
+ parent.appendChildren( el2 );
|
|
|
+ parent.appendChildren( el3 );
|
|
|
|
|
|
expect( parent.getChildCount() ).to.equal( 3 );
|
|
|
- expect( parent.getChildIndex( e1 ) ).to.equal( 0 );
|
|
|
- expect( parent.getChildIndex( e2 ) ).to.equal( 1 );
|
|
|
- expect( parent.getChildIndex( e3 ) ).to.equal( 2 );
|
|
|
+ expect( parent.getChildIndex( el1 ) ).to.equal( 0 );
|
|
|
+ expect( parent.getChildIndex( el2 ) ).to.equal( 1 );
|
|
|
+ expect( parent.getChildIndex( el3 ) ).to.equal( 2 );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'getChildren', () => {
|
|
|
it( 'should renturn children iterator', () => {
|
|
|
- parent.appendChildren( e1 );
|
|
|
- parent.appendChildren( e2 );
|
|
|
- parent.appendChildren( e3 );
|
|
|
+ parent.appendChildren( el1 );
|
|
|
+ parent.appendChildren( el2 );
|
|
|
+ parent.appendChildren( el3 );
|
|
|
|
|
|
- const expected = [ e1, e2, e3 ];
|
|
|
+ const expected = [ el1, el2, el3 ];
|
|
|
let i = 0;
|
|
|
|
|
|
for ( let child of parent.getChildren() ) {
|
|
|
@@ -120,59 +120,59 @@ describe( 'Element', () => {
|
|
|
|
|
|
describe( 'removeChildren', () => {
|
|
|
it( 'should remove children', () => {
|
|
|
- parent.appendChildren( e1 );
|
|
|
- parent.appendChildren( e2 );
|
|
|
- parent.appendChildren( e3 );
|
|
|
- parent.appendChildren( e4 );
|
|
|
+ parent.appendChildren( el1 );
|
|
|
+ parent.appendChildren( el2 );
|
|
|
+ parent.appendChildren( el3 );
|
|
|
+ parent.appendChildren( el4 );
|
|
|
|
|
|
parent.removeChildren( 1, 2 );
|
|
|
|
|
|
expect( parent.getChildCount() ).to.equal( 2 );
|
|
|
- expect( parent.getChild( 0 ) ).to.have.property( 'name' ).that.equals( 'e1' );
|
|
|
- expect( parent.getChild( 1 ) ).to.have.property( 'name' ).that.equals( 'e4' );
|
|
|
+ expect( parent.getChild( 0 ) ).to.have.property( 'name' ).that.equals( 'el1' );
|
|
|
+ expect( parent.getChild( 1 ) ).to.have.property( 'name' ).that.equals( 'el4' );
|
|
|
|
|
|
- expect( e1.parent ).to.equal( parent );
|
|
|
- expect( e2.parent ).to.be.null;
|
|
|
- expect( e3.parent ).to.be.null;
|
|
|
- expect( e4.parent ).equal( parent );
|
|
|
+ expect( el1.parent ).to.equal( parent );
|
|
|
+ expect( el2.parent ).to.be.null;
|
|
|
+ expect( el3.parent ).to.be.null;
|
|
|
+ expect( el4.parent ).equal( parent );
|
|
|
} );
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'attributes manipulation methods', () => {
|
|
|
- let elem;
|
|
|
+ let el;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
- elem = new ViewElement( 'p' );
|
|
|
+ el = new ViewElement( 'p' );
|
|
|
} );
|
|
|
|
|
|
describe( 'getAttr', () => {
|
|
|
it( 'should return attribute', () => {
|
|
|
- elem.setAttr( 'foo', 'bar' );
|
|
|
+ el.setAttr( 'foo', 'bar' );
|
|
|
|
|
|
- expect( elem.getAttr( 'foo' ) ).to.equal( 'bar' );
|
|
|
- expect( elem.getAttr( 'bom' ) ).to.not.be.ok;
|
|
|
+ expect( el.getAttr( 'foo' ) ).to.equal( 'bar' );
|
|
|
+ expect( el.getAttr( 'bom' ) ).to.not.be.ok;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'hasAttr', () => {
|
|
|
it( 'should return true if element has attribute', () => {
|
|
|
- elem.setAttr( 'foo', 'bar' );
|
|
|
+ el.setAttr( 'foo', 'bar' );
|
|
|
|
|
|
- expect( elem.hasAttr( 'foo' ) ).to.be.true;
|
|
|
- expect( elem.hasAttr( 'bom' ) ).to.be.false;
|
|
|
+ expect( el.hasAttr( 'foo' ) ).to.be.true;
|
|
|
+ expect( el.hasAttr( 'bom' ) ).to.be.false;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'getAttrKeys', () => {
|
|
|
it( 'should return keys', () => {
|
|
|
- elem.setAttr( 'foo', true );
|
|
|
- elem.setAttr( 'bar', true );
|
|
|
+ el.setAttr( 'foo', true );
|
|
|
+ el.setAttr( 'bar', true );
|
|
|
|
|
|
const expected = [ 'foo', 'bar' ];
|
|
|
let i = 0;
|
|
|
|
|
|
- for ( let child of elem.getAttrKeys() ) {
|
|
|
+ for ( let child of el.getAttrKeys() ) {
|
|
|
expect( child ).to.equal( expected[ i ] );
|
|
|
i++;
|
|
|
}
|
|
|
@@ -183,15 +183,15 @@ describe( 'Element', () => {
|
|
|
|
|
|
describe( 'removeAttr', () => {
|
|
|
it( 'should remove attributes', () => {
|
|
|
- elem.setAttr( 'foo', true );
|
|
|
+ el.setAttr( 'foo', true );
|
|
|
|
|
|
- expect( elem.hasAttr( 'foo' ) ).to.be.true;
|
|
|
+ expect( el.hasAttr( 'foo' ) ).to.be.true;
|
|
|
|
|
|
- elem.removeAttr( 'foo' );
|
|
|
+ el.removeAttr( 'foo' );
|
|
|
|
|
|
- expect( elem.hasAttr( 'foo' ) ).to.be.false;
|
|
|
+ expect( el.hasAttr( 'foo' ) ).to.be.false;
|
|
|
|
|
|
- expect( getIteratorCount( elem.getAttrKeys() ) ).to.equal( 0 );
|
|
|
+ expect( getIteratorCount( el.getAttrKeys() ) ).to.equal( 0 );
|
|
|
} );
|
|
|
} );
|
|
|
} );
|