|
|
@@ -188,7 +188,7 @@ describe( 'DataController', () => {
|
|
|
|
|
|
it( 'should get root name as a parameter', () => {
|
|
|
schema.extend( '$text', { allowIn: '$root' } );
|
|
|
- data.init( 'foo', 'title' );
|
|
|
+ data.init( { title: 'foo' } );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'foo' );
|
|
|
} );
|
|
|
@@ -248,8 +248,8 @@ describe( 'DataController', () => {
|
|
|
|
|
|
it( 'should get root name as a parameter', () => {
|
|
|
schema.extend( '$text', { allowIn: '$root' } );
|
|
|
- data.set( 'foo', 'main' );
|
|
|
- data.set( 'Bar', 'title' );
|
|
|
+ data.set( 'foo' );
|
|
|
+ data.set( { title: 'Bar' } );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true, rootName: 'main' } ) ).to.equal( 'foo' );
|
|
|
expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'Bar' );
|
|
|
@@ -260,7 +260,7 @@ describe( 'DataController', () => {
|
|
|
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' );
|
|
|
+ data.set( { title: 'Bar' } );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true, rootName: 'main' } ) ).to.equal( '' );
|
|
|
expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'Bar' );
|
|
|
@@ -273,14 +273,37 @@ describe( 'DataController', () => {
|
|
|
it( 'should allow setting empty data', () => {
|
|
|
schema.extend( '$text', { allowIn: '$root' } );
|
|
|
|
|
|
- data.set( 'foo', 'title' );
|
|
|
+ data.set( { title: 'foo' } );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'foo' );
|
|
|
|
|
|
- data.set( '', 'title' );
|
|
|
+ data.set( { title: '' } );
|
|
|
|
|
|
expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( '' );
|
|
|
} );
|
|
|
+
|
|
|
+ it( 'should throw an error when non-existent root is used (single)', () => {
|
|
|
+ expect( () => {
|
|
|
+ data.set( { nonexistent: '<p>Bar</p>' } );
|
|
|
+ } ).to.throw(
|
|
|
+ CKEditorError,
|
|
|
+ 'trying-to-set-data-on-non-existing-root: Attempting to set data on non-existing "nonexistent" root.'
|
|
|
+ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should throw an error when non-existent root is used (one of many) without touching any roots data', () => {
|
|
|
+ schema.extend( '$text', { allowIn: '$root' } );
|
|
|
+ data.set( 'foo' );
|
|
|
+
|
|
|
+ expect( () => {
|
|
|
+ data.set( { main: 'bar', nonexistent: '<p>Bar</p>' } );
|
|
|
+ } ).to.throw(
|
|
|
+ CKEditorError,
|
|
|
+ 'trying-to-set-data-on-non-existing-root: Attempting to set data on non-existing "nonexistent" root.'
|
|
|
+ );
|
|
|
+
|
|
|
+ expect( getData( model, { withoutSelection: true } ) ).to.equal( 'foo' );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
describe( 'get()', () => {
|