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

Commit

Permalink
Simplified tests for saving reference to the inserted object.
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Mar 22, 2017
1 parent a80abe3 commit afe5aab
Showing 1 changed file with 13 additions and 44 deletions.
57 changes: 13 additions & 44 deletions tests/controller/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import insertContent from '../../src/controller/insertcontent';

import DocumentFragment from '../../src/model/documentfragment';
import Text from '../../src/model/text';
import Element from '../../src/model/element';

import { setData, getData, parse } from '../../src/dev-utils/model';

Expand Down Expand Up @@ -62,55 +63,23 @@ describe( 'DataController', () => {
expect( getData( doc ) ).to.equal( 'xa[]x' );
} );

describe( 'saves the reference to the original object', () => {
it( 'inline-widget', () => {
doc = new Document();
doc.createRoot();

doc.schema.registerItem( 'paragraph', '$block' );
doc.schema.registerItem( 'inlineWidget' );
doc.schema.allow( { name: 'inlineWidget', inside: '$block' } );
doc.schema.allow( { name: 'inlineWidget', inside: '$clipboardHolder' } );
doc.schema.objects.add( 'inlineWidget' );

dataController = new DataController( doc );

const batch = doc.batch();

setData( doc, '<paragraph>f[]oo</paragraph>' );

const content = parse( '<inlineWidget></inlineWidget>', doc.schema, {
context: [ '$clipboardHolder' ]
} );

insertContent( dataController, content, doc.selection, batch );

expect( doc.getRoot().getChild( 0 ).getChild( 1 ) ).to.equal( content );
} );

it( 'image', () => {
doc = new Document();
doc.createRoot();

doc.schema.registerItem( 'paragraph', '$block' );
doc.schema.registerItem( 'image', '$inline' );
doc.schema.allow( { name: 'image', inside: '$clipboardHolder' } );
doc.schema.objects.add( 'image' );

dataController = new DataController( doc );
it( 'should save the reference to the original object', () => {
const doc = new Document();
const dataController = new DataController( doc );
const batch = doc.batch();
const content = new Element( 'image' );

const batch = doc.batch();
doc.createRoot();

setData( doc, '<paragraph>foo[]</paragraph>' );
doc.schema.registerItem( 'paragraph', '$block' );
doc.schema.registerItem( 'image', '$inline' );
doc.schema.objects.add( 'image' );

const content = parse( '<image></image>', doc.schema, {
context: [ '$clipboardHolder' ]
} );
setData( doc, '<paragraph>foo[]</paragraph>' );

insertContent( dataController, content, doc.selection, batch );
insertContent( dataController, content, doc.selection, batch );

expect( doc.getRoot().getChild( 0 ).getChild( 1 ) ).to.equal( content );
} );
expect( doc.getRoot().getChild( 0 ).getChild( 1 ) ).to.equal( content );
} );

describe( 'in simple scenarios', () => {
Expand Down

0 comments on commit afe5aab

Please sign in to comment.