Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it( 'should skip filler', () => {
// eslint-disable-next-line new-cap
const domFiller = BR_FILLER( document );
const domP = createElement( document, 'p', null, domFiller );
const viewChildren = Array.from( converter.domChildrenToView( domP ) );
expect( viewChildren.length ).to.equal( 0 );
} );
it( 'should return corresponding view text based on sibling', () => {
const domImg = document.createElement( 'img' );
const domText = document.createTextNode( 'foo' );
const domP = createElement( document, 'p', null, [ domImg, domText ] );
const viewImg = new ViewElement( 'img' );
converter.bindElements( domImg, viewImg );
const viewP = converter.domToView( domP );
const viewText = viewP.getChild( 1 );
expect( converter.findCorrespondingViewText( domText ) ).to.equal( viewText );
} );
it( 'spaces in a text node: ' + inputTexts.join( '|' ) + ' -> ' + output, () => {
const domElement = createElement( document, 'div', {}, [] );
for ( const text of inputTexts ) {
domElement.appendChild( document.createTextNode( text.replace( /_/g, '\u00A0' ) ) );
}
const viewElement = converter.domToView( domElement );
let data = '';
for ( const child of viewElement.getChildren() ) {
data += child.data.replace( /\u00A0/g, '_' );
}
expect( data ).to.equal( output );
} );
}
it( 'should return corresponding view text based on parent', () => {
const domText = document.createTextNode( 'foo' );
const domP = createElement( document, 'p', null, domText );
const viewP = converter.domToView( domP );
const viewText = viewP.getChild( 0 );
converter.bindElements( domP, viewP );
expect( converter.findCorrespondingViewText( domText ) ).to.equal( viewText );
} );
it( 'should converter position in element', () => {
const domText = document.createTextNode( 'foo' );
const domB = createElement( document, 'b', null, 'bar' );
const domP = createElement( document, 'p', null, [ domText, domB ] );
const viewP = parse( '<p>foo<b>bar</b></p>' );
converter.bindElements( domP, viewP );
converter.bindElements( domB, viewP.getChild( 0 ) );
const viewPosition = converter.domPositionToView( domP, 1 );
expect( stringify( viewP, viewPosition ) ).to.equal( '<p>foo[]<b>bar</b></p>' );
} );
it( 'should convert view range to DOM range', () => {
const domFoo = document.createTextNode( 'foo' );
const domP = createElement( document, 'p', null, domFoo );
const { view: viewP, selection } = parse( 'fo{o]' );
converter.bindElements( domP, viewP );
const viewRange = selection.getFirstRange();
const domRange = converter.viewRangeToDom( viewRange );
expect( domRange ).to.be.instanceof( Range );
expect( domRange.startContainer ).to.equal( domFoo );
expect( domRange.startOffset ).to.equal( 2 );
expect( domRange.endContainer ).to.equal( domP );
expect( domRange.endOffset ).to.equal( 1 );
} );
} );
it( 'should return null if there is no child text node in view', () => {
const domText = document.createTextNode( 'x' );
const domP = createElement( document, 'p', null, domText );
const viewP = parse( '<p></p>' );
converter.bindElements( domP, viewP );
expect( converter.findCorrespondingViewText( domText ) ).to.be.null;
} );
} );
it( 'should remove content of the DOM', () => {
const domDiv = createElement( document, 'div', { id: 'editor' }, [
createElement( document, 'p' ),
createElement( document, 'p' )
] );
const viewDocument = new Document();
viewDocument.createRoot( domDiv );
viewDocument.render();
expect( domDiv.childNodes.length ).to.equal( 1 );
expect( isBlockFiller( domDiv.childNodes[ 0 ], BR_FILLER ) ).to.be.true;
viewDocument.destroy();
} );
it( 'should return null if start or end is null', () => {
const domFoo = document.createTextNode( 'foo' );
const domBar = document.createTextNode( 'bar' );
const domB = createElement( document, 'b', null, domBar );
createElement( document, 'p', null, [ domFoo, domB ] );
const domRange = document.createRange();
domRange.setStart( domFoo, 1 );
domRange.setEnd( domBar, 2 );
const viewRange = converter.domRangeToView( domRange );
expect( viewRange ).to.be.null;
} );
} );
it( 'should not add null ranges', () => {
const domFoo = document.createTextNode( 'foo' );
const domBar = document.createTextNode( 'bar' );
const domB = createElement( document, 'b', null, domBar );
const domP = createElement( document, 'p', null, [ domFoo, domB ] );
document.body.appendChild( domP );
const domRange = document.createRange();
domRange.setStart( domFoo, 1 );
domRange.setEnd( domBar, 2 );
const domSelection = document.getSelection();
domSelection.removeAllRanges();
domSelection.addRange( domRange );
const viewSelection = converter.domSelectionToView( domSelection );
expect( viewSelection.rangeCount ).to.equal( 0 );
domP.remove();