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

Commit

Permalink
Fix: dev-utils/model#setData() should work with custom roots. Closes …
Browse files Browse the repository at this point in the history
…#815.
  • Loading branch information
szymonkups authored Feb 13, 2017
2 parents 973f2ba + 4b637fd commit 0ad3074
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/dev-utils/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export function setData( document, data, options = {} ) {
// Parse data string to model.
const parsedResult = setData._parse( data, document.schema, {
lastRangeBackward: options.lastRangeBackward,
selectionAttributes: options.selectionAttributes
selectionAttributes: options.selectionAttributes,
context: [ modelRoot.name ]
} );

// Retrieve DocumentFragment and Selection from parsed model.
Expand Down
4 changes: 2 additions & 2 deletions tests/controller/deletecontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ describe( 'DataController', () => {
it( 'deletes two inline elements', () => {
setData(
doc,
'<paragraph>x[<image></image><image></image>]z</paragraph>',
'x[<image></image><image></image>]z',
{ rootName: 'paragraphRoot' }
);

deleteContent( doc.selection, doc.batch() );

expect( getData( doc, { rootName: 'paragraphRoot' } ) )
.to.equal( '<paragraph>x[]z</paragraph>' );
.to.equal( 'x[]z' );
} );

it( 'creates a paragraph when text is not allowed (paragraph selected)', () => {
Expand Down
12 changes: 12 additions & 0 deletions tests/dev-utils/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ describe( 'model test utils', () => {
expect( document.selection.getAttribute( 'foo' ) ).to.equal( 'bar' );
} );

// #815.
it( 'should work in a special root', () => {
const document = new Document();

document.schema.registerItem( 'textOnly' );
document.schema.allow( { name: '$text', inside: 'textOnly' } );
document.createRoot( 'textOnly', 'textOnly' );

setData( document, 'a[b]c', { rootName: 'textOnly' } );
expect( getData( document, { rootName: 'textOnly' } ) ).to.equal( 'a[b]c' );
} );

function test( data, expected ) {
expected = expected || data;

Expand Down

0 comments on commit 0ad3074

Please sign in to comment.