| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- /**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* bender-tags: treeview */
- 'use strict';
- const modules = bender.amd.require(
- 'core/treeview/node',
- 'core/treeview/element',
- 'core/treeview/text'
- );
- describe( 'Element', () => {
- let ViewText, ViewElement, ViewNode;
- before( () => {
- ViewText = modules[ 'core/treeview/text' ];
- ViewElement = modules[ 'core/treeview/element' ];
- ViewNode = modules[ 'core/treeview/node' ];
- } );
- describe( 'constructor', () => {
- it( 'should create element without attributes', () => {
- const text = new ViewText( 'foo' );
- expect( text ).to.be.an.instanceof( ViewNode );
- expect( text.getText() ).to.equal( 'foo' );
- expect( text ).to.have.property( 'parent' ).that.is.null;
- } );
- } );
- describe( 'setText', () => {
- it( 'should change the text', () => {
- const text = new ViewText( 'foo' );
- text.setText( 'bar' );
- expect( text.getText() ).to.equal( 'bar' );
- } );
- } );
- describe( 'DOM-View binding', () => {
- describe( 'getCorespondingView', () => {
- it( 'should return coresponding view element based on sibling', () => {
- const domImg = document.createElement( 'img' );
- const domText = document.createTextNode( 'foo' );
- const domP = document.createElement( 'p' );
- domP.appendChild( domImg );
- domP.appendChild( domText );
- const viewImg = new ViewElement( 'img' );
- viewImg.bindDomElement( domImg );
- const viewP = ViewElement.createFromDom( domP );
- const viewText = viewP.getChild( 1 );
- expect( ViewText.getCorespondingView( domText ) ).to.equal( viewText );
- } );
- it( 'should return coresponding view element based on parent', () => {
- const domText = document.createTextNode( 'foo' );
- const domP = document.createElement( 'p' );
- domP.appendChild( domText );
- const viewP = ViewElement.createFromDom( domP );
- const viewText = viewP.getChild( 0 );
- viewP.bindDomElement( domP );
- expect( ViewText.getCorespondingView( domText ) ).to.equal( viewText );
- } );
- it( 'should return null if sibling is not binded', () => {
- const domImg = document.createElement( 'img' );
- const domText = document.createTextNode( 'foo' );
- const domP = document.createElement( 'p' );
- domP.appendChild( domImg );
- domP.appendChild( domText );
- const viewP = ViewElement.createFromDom( domP );
- viewP.bindDomElement( domP );
- expect( ViewText.getCorespondingView( domText ) ).to.be.null;
- } );
- it( 'should return null if parent is not binded', () => {
- const domText = document.createTextNode( 'foo' );
- const domP = document.createElement( 'p' );
- domP.appendChild( domText );
- expect( ViewText.getCorespondingView( domText ) ).to.be.null;
- } );
- } );
- describe( 'getCorespondingDom', () => {
- it( 'should return coresponding DOM element based on sibling', () => {
- const domImg = document.createElement( 'img' );
- const domText = document.createTextNode( 'foo' );
- const domP = document.createElement( 'p' );
- domP.appendChild( domImg );
- domP.appendChild( domText );
- const viewImg = new ViewElement( 'img' );
- viewImg.bindDomElement( domImg );
- const viewP = ViewElement.createFromDom( domP );
- const viewText = viewP.getChild( 1 );
- expect( viewText.getCorespondingDom() ).to.equal( domText );
- } );
- it( 'should return coresponding DOM element based on parent', () => {
- const domText = document.createTextNode( 'foo' );
- const domP = document.createElement( 'p' );
- domP.appendChild( domText );
- const viewP = ViewElement.createFromDom( domP );
- const viewText = viewP.getChild( 0 );
- viewP.bindDomElement( domP );
- expect( viewText.getCorespondingDom() ).to.equal( domText );
- } );
- it( 'should return null if sibling is not binded', () => {
- const domImg = document.createElement( 'img' );
- const domText = document.createTextNode( 'foo' );
- const domP = document.createElement( 'p' );
- domP.appendChild( domImg );
- domP.appendChild( domText );
- const viewP = ViewElement.createFromDom( domP );
- const viewText = viewP.getChild( 1 );
- viewP.bindDomElement( domP );
- expect( viewText.getCorespondingDom() ).to.be.null;
- } );
- it( 'should return null if parent is not binded', () => {
- const domText = document.createTextNode( 'foo' );
- const domP = document.createElement( 'p' );
- domP.appendChild( domText );
- const viewP = ViewElement.createFromDom( domP );
- const viewText = viewP.getChild( 0 );
- expect( viewText.getCorespondingDom() ).to.be.null;
- } );
- } );
- } );
- } );
|