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

Commit

Permalink
Fix: Added missing parse context in DataController#set().
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Feb 6, 2018
1 parent b017890 commit 8e3694a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default class DataController {
writer.removeSelectionAttribute( this.model.document.selection.getAttributeKeys() );

writer.remove( ModelRange.createIn( modelRoot ) );
writer.insert( this.parse( data ), modelRoot );
writer.insert( this.parse( data, modelRoot ), modelRoot );
} );
}

Expand Down
22 changes: 18 additions & 4 deletions tests/controller/datacontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ describe( 'DataController', () => {

beforeEach( () => {
model = new Model();

schema = model.schema;
modelDocument = model.document;

modelDocument.createRoot();
modelDocument.createRoot( '$root', 'title' );
modelDocument.createRoot( '$title', 'title' );

schema.register( '$title', { inheritAllFrom: '$root' } );

htmlDataProcessor = new HtmlDataProcessor();

data = new DataController( model, htmlDataProcessor );

schema = model.schema;
} );

describe( 'constructor()', () => {
Expand Down Expand Up @@ -143,7 +146,7 @@ describe( 'DataController', () => {
} );

describe( 'set()', () => {
it( 'should set data to root', () => {
it( 'should set data to default main root', () => {
schema.extend( '$text', { allowIn: '$root' } );
data.set( 'foo' );

Expand Down Expand Up @@ -179,6 +182,17 @@ describe( 'DataController', () => {
expect( count( modelDocument.history.getDeltas() ) ).to.equal( 2 );
} );

it( 'should parse given data before set in a context of correct root', () => {
schema.extend( '$text', { allowIn: '$title', disallowIn: '$root' } );
data.set( 'foo', 'main' );
data.set( 'Bar', 'title' );

expect( getData( model, { withoutSelection: true, rootName: 'main' } ) ).to.equal( '' );
expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'Bar' );

expect( count( modelDocument.history.getDeltas() ) ).to.equal( 2 );
} );

// This case was added when order of params was different and it really didn't work. Let's keep it
// if anyone will ever try to change this.
it( 'should allow setting empty data', () => {
Expand Down

0 comments on commit 8e3694a

Please sign in to comment.