|
|
@@ -3,7 +3,9 @@
|
|
|
* For licensing, see LICENSE.md.
|
|
|
*/
|
|
|
|
|
|
+import DocumentFragment from '../../src/view/documentfragment';
|
|
|
import Element from '../../src/view/element';
|
|
|
+import Text from '../../src/view/text';
|
|
|
import UpcastWriter from '../../src/view/upcastwriter';
|
|
|
import HtmlDataProcessor from '../../src/dataprocessor/htmldataprocessor';
|
|
|
|
|
|
@@ -29,6 +31,71 @@ describe( 'UpcastWriter', () => {
|
|
|
view = dataprocessor.toView( html );
|
|
|
} );
|
|
|
|
|
|
+ describe( 'createDocumentFragment', () => {
|
|
|
+ it( 'should create empty document fragment', () => {
|
|
|
+ const df = writer.createDocumentFragment();
|
|
|
+
|
|
|
+ expect( df ).to.instanceOf( DocumentFragment );
|
|
|
+ expect( df.childCount ).to.equal( 0 );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should create document fragment with children', () => {
|
|
|
+ const df = writer.createDocumentFragment( [ view.getChild( 0 ), view.getChild( 1 ) ] );
|
|
|
+
|
|
|
+ expect( df ).to.instanceOf( DocumentFragment );
|
|
|
+ expect( df.childCount ).to.equal( 2 );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'createElement', () => {
|
|
|
+ it( 'should create empty element', () => {
|
|
|
+ const el = writer.createElement( 'p' );
|
|
|
+
|
|
|
+ expect( el ).to.instanceOf( Element );
|
|
|
+ expect( el.name ).to.equal( 'p' );
|
|
|
+ expect( Array.from( el.getAttributes() ).length ).to.equal( 0 );
|
|
|
+ expect( el.childCount ).to.equal( 0 );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should create element with attributes', () => {
|
|
|
+ const el = writer.createElement( 'a', { 'class': 'editor', 'contentEditable': 'true' } );
|
|
|
+
|
|
|
+ expect( el ).to.instanceOf( Element );
|
|
|
+ expect( el.name ).to.equal( 'a' );
|
|
|
+ expect( Array.from( el.getAttributes() ).length ).to.equal( 2 );
|
|
|
+ expect( el.childCount ).to.equal( 0 );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should create element with children', () => {
|
|
|
+ const el = writer.createElement( 'div', null, [ view.getChild( 0 ) ] );
|
|
|
+
|
|
|
+ expect( el ).to.instanceOf( Element );
|
|
|
+ expect( el.name ).to.equal( 'div' );
|
|
|
+ expect( Array.from( el.getAttributes() ).length ).to.equal( 0 );
|
|
|
+ expect( el.childCount ).to.equal( 1 );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should create element with attributes and children', () => {
|
|
|
+ const el = writer.createElement( 'blockquote',
|
|
|
+ { 'class': 'editor', 'contentEditable': 'true' },
|
|
|
+ view.getChild( 2 ) );
|
|
|
+
|
|
|
+ expect( el ).to.instanceOf( Element );
|
|
|
+ expect( el.name ).to.equal( 'blockquote' );
|
|
|
+ expect( Array.from( el.getAttributes() ).length ).to.equal( 2 );
|
|
|
+ expect( el.childCount ).to.equal( 1 );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( 'createText', () => {
|
|
|
+ it( 'should create text', () => {
|
|
|
+ const text = writer.createText( 'FooBar' );
|
|
|
+
|
|
|
+ expect( text ).to.instanceOf( Text );
|
|
|
+ expect( text.data ).to.equal( 'FooBar' );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
describe( 'clone', () => {
|
|
|
it( 'should clone simple element', () => {
|
|
|
const el = view.getChild( 0 );
|