Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge 6ce1421 into ef5960e
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Aug 20, 2018
2 parents ef5960e + 6ce1421 commit 43a7972
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/dev-utils/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @module engine/dev-utils/view
*/

/* globals document */

/**
* Collection of methods for manipulating the {@link module:engine/view/view view} for testing purposes.
*/
Expand Down Expand Up @@ -652,13 +654,17 @@ class ViewStringify {
callback( this._stringifyElementOpen( root ) );
}

let offset = 0;
callback( this._stringifyElementRanges( root, offset ) );

for ( const child of root.getChildren() ) {
this._walkView( child, callback );
offset++;
if ( root.is( 'uiElement' ) ) {
callback( root.render( document ).innerHTML );
} else {
let offset = 0;
callback( this._stringifyElementRanges( root, offset ) );

for ( const child of root.getChildren() ) {
this._walkView( child, callback );
offset++;
callback( this._stringifyElementRanges( root, offset ) );
}
}

if ( root.is( 'element' ) && !ignore ) {
Expand Down
16 changes: 16 additions & 0 deletions tests/dev-utils/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,22 @@ describe( 'view test utils', () => {
.to.equal( '<container:p><ui:span></ui:span></container:p>' );
} );

it( 'should stringify UIElement (custom render function)', () => {
const span = new UIElement( 'span' );

span.render = function( domDocument ) {
const domElement = this.toDomElement( domDocument );

domElement.innerHTML = '<b>foo</b>';

return domElement;
};

const p = new ContainerElement( 'p', null, span );
expect( stringify( p, null, { showType: true } ) )
.to.equal( '<container:p><ui:span><b>foo</b></ui:span></container:p>' );
} );

it( 'should sort classes in specified element', () => {
const text = new Text( 'foobar' );
const b = new Element( 'b', {
Expand Down

0 comments on commit 43a7972

Please sign in to comment.