@@ -25,15 +25,18 @@ describe( 'DataController', () => {
2525
2626 beforeEach ( ( ) => {
2727 model = new Model ( ) ;
28+
29+ schema = model . schema ;
2830 modelDocument = model . document ;
31+
2932 modelDocument . createRoot ( ) ;
30- modelDocument . createRoot ( '$root' , 'title' ) ;
33+ modelDocument . createRoot ( '$title' , 'title' ) ;
34+
35+ schema . register ( '$title' , { inheritAllFrom : '$root' } ) ;
3136
3237 htmlDataProcessor = new HtmlDataProcessor ( ) ;
3338
3439 data = new DataController ( model , htmlDataProcessor ) ;
35-
36- schema = model . schema ;
3740 } ) ;
3841
3942 describe ( 'constructor()' , ( ) => {
@@ -143,7 +146,7 @@ describe( 'DataController', () => {
143146 } ) ;
144147
145148 describe ( 'set()' , ( ) => {
146- it ( 'should set data to root' , ( ) => {
149+ it ( 'should set data to default main root' , ( ) => {
147150 schema . extend ( '$text' , { allowIn : '$root' } ) ;
148151 data . set ( 'foo' ) ;
149152
@@ -179,6 +182,17 @@ describe( 'DataController', () => {
179182 expect ( count ( modelDocument . history . getDeltas ( ) ) ) . to . equal ( 2 ) ;
180183 } ) ;
181184
185+ it ( 'should parse given data before set in a context of correct root' , ( ) => {
186+ schema . extend ( '$text' , { allowIn : '$title' , disallowIn : '$root' } ) ;
187+ data . set ( 'foo' , 'main' ) ;
188+ data . set ( 'Bar' , 'title' ) ;
189+
190+ expect ( getData ( model , { withoutSelection : true , rootName : 'main' } ) ) . to . equal ( '' ) ;
191+ expect ( getData ( model , { withoutSelection : true , rootName : 'title' } ) ) . to . equal ( 'Bar' ) ;
192+
193+ expect ( count ( modelDocument . history . getDeltas ( ) ) ) . to . equal ( 2 ) ;
194+ } ) ;
195+
182196 // This case was added when order of params was different and it really didn't work. Let's keep it
183197 // if anyone will ever try to change this.
184198 it ( 'should allow setting empty data' , ( ) => {
0 commit comments