| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /**
- * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* globals document */
- /* bender-tags: dom, browser-only */
- import insertAt from 'ckeditor5/utils/dom/insertat.js';
- describe( 'insertAt', () => {
- it( 'should insert at given position', () => {
- const div = document.createElement( 'div' );
- const p0 = document.createElement( 'p' );
- const p1 = document.createElement( 'p' );
- const p2 = document.createElement( 'p' );
- div.appendChild( p0 );
- div.appendChild( p2 );
- insertAt( div, 1, p1 );
- expect( div.childNodes.length ).to.equal( 3 );
- expect( div.childNodes[ 0 ] ).to.equal( p0 );
- expect( div.childNodes[ 1 ] ).to.equal( p1 );
- expect( div.childNodes[ 2 ] ).to.equal( p2 );
- } );
- it( 'should insert at the beginning', () => {
- const div = document.createElement( 'div' );
- const p0 = document.createElement( 'p' );
- const p1 = document.createElement( 'p' );
- const p2 = document.createElement( 'p' );
- div.appendChild( p1 );
- div.appendChild( p2 );
- insertAt( div, 0, p0 );
- expect( div.childNodes.length ).to.equal( 3 );
- expect( div.childNodes[ 0 ] ).to.equal( p0 );
- expect( div.childNodes[ 1 ] ).to.equal( p1 );
- expect( div.childNodes[ 2 ] ).to.equal( p2 );
- } );
- it( 'should insert at the end', () => {
- const div = document.createElement( 'div' );
- const p0 = document.createElement( 'p' );
- const p1 = document.createElement( 'p' );
- const p2 = document.createElement( 'p' );
- div.appendChild( p0 );
- div.appendChild( p1 );
- insertAt( div, 2, p2 );
- expect( div.childNodes.length ).to.equal( 3 );
- expect( div.childNodes[ 0 ] ).to.equal( p0 );
- expect( div.childNodes[ 1 ] ).to.equal( p1 );
- expect( div.childNodes[ 2 ] ).to.equal( p2 );
- } );
- } );
|