datacontroller.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import Model from '../../src/model/model';
  6. import ModelRange from '../../src/model/range';
  7. import ViewRange from '../../src/view/range';
  8. import DataController from '../../src/controller/datacontroller';
  9. import HtmlDataProcessor from '../../src/dataprocessor/htmldataprocessor';
  10. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  11. import ModelDocumentFragment from '../../src/model/documentfragment';
  12. import ViewDocumentFragment from '../../src/view/documentfragment';
  13. import { getData, setData, stringify, parse as parseModel } from '../../src/dev-utils/model';
  14. import { parse as parseView, stringify as stringifyView } from '../../src/dev-utils/view';
  15. import count from '@ckeditor/ckeditor5-utils/src/count';
  16. import UpcastHelpers from '../../src/conversion/upcasthelpers';
  17. import DowncastHelpers from '../../src/conversion/downcasthelpers';
  18. describe( 'DataController', () => {
  19. let model, modelDocument, htmlDataProcessor, data, schema, upcastHelpers, downcastHelpers;
  20. beforeEach( () => {
  21. model = new Model();
  22. schema = model.schema;
  23. modelDocument = model.document;
  24. modelDocument.createRoot();
  25. modelDocument.createRoot( '$title', 'title' );
  26. schema.register( '$title', { inheritAllFrom: '$root' } );
  27. htmlDataProcessor = new HtmlDataProcessor();
  28. data = new DataController( model, htmlDataProcessor );
  29. upcastHelpers = new UpcastHelpers( [ data.upcastDispatcher ] );
  30. downcastHelpers = new DowncastHelpers( [ data.downcastDispatcher ] );
  31. } );
  32. describe( 'constructor()', () => {
  33. it( 'works without data processor', () => {
  34. const data = new DataController( model );
  35. expect( data.processor ).to.be.undefined;
  36. } );
  37. } );
  38. describe( 'parse()', () => {
  39. it( 'should set text', () => {
  40. schema.extend( '$text', { allowIn: '$root' } );
  41. const output = data.parse( '<p>foo<b>bar</b></p>' );
  42. expect( output ).to.instanceof( ModelDocumentFragment );
  43. expect( stringify( output ) ).to.equal( 'foobar' );
  44. } );
  45. it( 'should set paragraph', () => {
  46. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  47. upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
  48. const output = data.parse( '<p>foo<b>bar</b></p>' );
  49. expect( output ).to.instanceof( ModelDocumentFragment );
  50. expect( stringify( output ) ).to.equal( '<paragraph>foobar</paragraph>' );
  51. } );
  52. it( 'should set two paragraphs', () => {
  53. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  54. upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
  55. const output = data.parse( '<p>foo</p><p>bar</p>' );
  56. expect( output ).to.instanceof( ModelDocumentFragment );
  57. expect( stringify( output ) ).to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
  58. } );
  59. it( 'should set paragraphs with bold', () => {
  60. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  61. schema.extend( '$text', {
  62. allowAttributes: [ 'bold' ]
  63. } );
  64. upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
  65. upcastHelpers.elementToAttribute( { view: 'strong', model: 'bold' } );
  66. const output = data.parse( '<p>foo<strong>bar</strong></p>' );
  67. expect( output ).to.instanceof( ModelDocumentFragment );
  68. expect( stringify( output ) ).to.equal( '<paragraph>foo<$text bold="true">bar</$text></paragraph>' );
  69. } );
  70. it( 'should parse in the root context by default', () => {
  71. const output = data.parse( 'foo' );
  72. expect( stringify( output ) ).to.equal( '' );
  73. } );
  74. it( 'should accept parsing context', () => {
  75. const output = data.parse( 'foo', [ '$block' ] );
  76. expect( stringify( output ) ).to.equal( 'foo' );
  77. } );
  78. } );
  79. describe( 'toModel()', () => {
  80. beforeEach( () => {
  81. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  82. upcastHelpers.elementToElement( { view: 'p', model: 'paragraph' } );
  83. } );
  84. it( 'should convert content of an element #1', () => {
  85. const viewElement = parseView( '<p>foo</p>' );
  86. const output = data.toModel( viewElement );
  87. expect( output ).to.instanceof( ModelDocumentFragment );
  88. expect( stringify( output ) ).to.equal( '<paragraph>foo</paragraph>' );
  89. } );
  90. it( 'should convert content of an element #2', () => {
  91. const viewFragment = parseView( '<p>foo</p><p>bar</p>' );
  92. const output = data.toModel( viewFragment );
  93. expect( output ).to.be.instanceOf( ModelDocumentFragment );
  94. expect( stringify( output ) ).to.equal( '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
  95. } );
  96. it( 'should accept parsing context', () => {
  97. modelDocument.createRoot( 'inlineRoot', 'inlineRoot' );
  98. schema.register( 'inlineRoot' );
  99. schema.extend( '$text', { allowIn: 'inlineRoot' } );
  100. const viewFragment = new ViewDocumentFragment( [ parseView( 'foo' ) ] );
  101. // Model fragment in root.
  102. expect( stringify( data.toModel( viewFragment ) ) ).to.equal( '' );
  103. // Model fragment in inline root.
  104. expect( stringify( data.toModel( viewFragment, [ 'inlineRoot' ] ) ) ).to.equal( 'foo' );
  105. } );
  106. } );
  107. describe( 'init()', () => {
  108. it( 'should be decorated', () => {
  109. const spy = sinon.spy();
  110. data.on( 'init', spy );
  111. data.init( 'foo bar' );
  112. sinon.assert.calledWithExactly( spy, sinon.match.any, [ 'foo bar' ] );
  113. } );
  114. it( 'should fire ready event after init', () => {
  115. const spy = sinon.spy();
  116. data.on( 'ready', spy );
  117. data.init( 'foo bar' );
  118. sinon.assert.called( spy );
  119. } );
  120. it( 'should throw an error when document data is already initialized', () => {
  121. data.init( '<p>Foo</p>' );
  122. expect( () => {
  123. data.init( '<p>Bar</p>' );
  124. } ).to.throw(
  125. CKEditorError,
  126. 'datacontroller-init-document-not-empty: Trying to set initial data to not empty document.'
  127. );
  128. } );
  129. it( 'should set data to default main root', () => {
  130. schema.extend( '$text', { allowIn: '$root' } );
  131. data.init( 'foo' );
  132. expect( getData( model, { withoutSelection: true } ) ).to.equal( 'foo' );
  133. } );
  134. it( 'should set data to multiple roots at once', () => {
  135. schema.extend( '$text', { allowIn: '$root' } );
  136. data.init( { main: 'bar', title: 'baz' } );
  137. expect( getData( model, { withoutSelection: true } ) ).to.equal( 'bar' );
  138. expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'baz' );
  139. } );
  140. it( 'should get root name as a parameter', () => {
  141. schema.extend( '$text', { allowIn: '$root' } );
  142. data.init( { title: 'foo' } );
  143. expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'foo' );
  144. } );
  145. it( 'should create a batch', () => {
  146. schema.extend( '$text', { allowIn: '$root' } );
  147. data.init( 'foo' );
  148. expect( count( modelDocument.history.getOperations() ) ).to.equal( 1 );
  149. } );
  150. it( 'should cause firing change event', () => {
  151. const spy = sinon.spy();
  152. schema.extend( '$text', { allowIn: '$root' } );
  153. model.document.on( 'change', spy );
  154. data.init( 'foo' );
  155. expect( spy.calledOnce ).to.be.true;
  156. } );
  157. it( 'should return a resolved Promise', () => {
  158. const promise = data.init( '<p>Foo</p>' );
  159. expect( promise ).to.be.instanceof( Promise );
  160. return promise;
  161. } );
  162. it( 'should throw an error when non-existent root is used (single)', () => {
  163. expect( () => {
  164. data.init( { nonexistent: '<p>Bar</p>' } );
  165. } ).to.throw(
  166. CKEditorError,
  167. 'datacontroller-init-non-existent-root: Attempting to init data on a non-existing root.'
  168. );
  169. } );
  170. it( 'should throw an error when non-existent root is used (one of many)', () => {
  171. schema.extend( '$text', { allowIn: '$root' } );
  172. expect( () => {
  173. data.init( { main: 'bar', nonexistent: '<p>Bar</p>' } );
  174. } ).to.throw(
  175. CKEditorError,
  176. 'datacontroller-init-non-existent-root: Attempting to init data on a non-existing root.'
  177. );
  178. expect( getData( model, { withoutSelection: true } ) ).to.equal( '' );
  179. } );
  180. } );
  181. describe( 'set()', () => {
  182. it( 'should set data to default main root', () => {
  183. schema.extend( '$text', { allowIn: '$root' } );
  184. data.set( 'foo' );
  185. expect( getData( model, { withoutSelection: true } ) ).to.equal( 'foo' );
  186. } );
  187. it( 'should create a batch', () => {
  188. schema.extend( '$text', { allowIn: '$root' } );
  189. data.set( 'foo' );
  190. expect( count( modelDocument.history.getOperations() ) ).to.equal( 1 );
  191. } );
  192. it( 'should cause firing change event', () => {
  193. const spy = sinon.spy();
  194. schema.extend( '$text', { allowIn: '$root' } );
  195. model.document.on( 'change', spy );
  196. data.set( 'foo' );
  197. expect( spy.calledOnce ).to.be.true;
  198. } );
  199. it( 'should get root name as a parameter', () => {
  200. schema.extend( '$text', { allowIn: '$root' } );
  201. data.set( 'foo' );
  202. data.set( { title: 'Bar' } );
  203. expect( getData( model, { withoutSelection: true, rootName: 'main' } ) ).to.equal( 'foo' );
  204. expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'Bar' );
  205. expect( count( modelDocument.history.getOperations() ) ).to.equal( 2 );
  206. } );
  207. it( 'should parse given data before set in a context of correct root', () => {
  208. schema.extend( '$text', { allowIn: '$title', disallowIn: '$root' } );
  209. data.set( 'foo', 'main' );
  210. data.set( { title: 'Bar' } );
  211. expect( getData( model, { withoutSelection: true, rootName: 'main' } ) ).to.equal( '' );
  212. expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'Bar' );
  213. expect( count( modelDocument.history.getOperations() ) ).to.equal( 2 );
  214. } );
  215. // This case was added when order of params was different and it really didn't work. Let's keep it
  216. // if anyone will ever try to change this.
  217. it( 'should allow setting empty data', () => {
  218. schema.extend( '$text', { allowIn: '$root' } );
  219. data.set( { title: 'foo' } );
  220. expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( 'foo' );
  221. data.set( { title: '' } );
  222. expect( getData( model, { withoutSelection: true, rootName: 'title' } ) ).to.equal( '' );
  223. } );
  224. it( 'should throw an error when non-existent root is used (single)', () => {
  225. expect( () => {
  226. data.set( { nonexistent: '<p>Bar</p>' } );
  227. } ).to.throw(
  228. CKEditorError,
  229. 'datacontroller-set-non-existent-root: Attempting to set data on a non-existing root.'
  230. );
  231. } );
  232. it( 'should throw an error when non-existent root is used (one of many) without touching any roots data', () => {
  233. schema.extend( '$text', { allowIn: '$root' } );
  234. data.set( 'foo' );
  235. expect( () => {
  236. data.set( { main: 'bar', nonexistent: '<p>Bar</p>' } );
  237. } ).to.throw(
  238. CKEditorError,
  239. 'datacontroller-set-non-existent-root: Attempting to set data on a non-existing root.'
  240. );
  241. expect( getData( model, { withoutSelection: true } ) ).to.equal( 'foo' );
  242. } );
  243. // https://github.com/ckeditor/ckeditor5-engine/issues/1721.
  244. it( 'should not throw when setting the data with markers that already exist in the editor', () => {
  245. schema.extend( '$text', { allowIn: '$root' } );
  246. data.set( 'foo' );
  247. downcastHelpers.markerToElement( { model: 'marker', view: 'marker' } );
  248. upcastHelpers.elementToMarker( { view: 'marker', model: 'marker' } );
  249. model.change( writer => {
  250. writer.addMarker( 'marker', { range: writer.createRangeIn( modelDocument.getRoot() ), usingOperation: true } );
  251. } );
  252. expect( () => {
  253. data.set( data.get() );
  254. } ).not.to.throw();
  255. } );
  256. } );
  257. describe( 'get()', () => {
  258. it( 'should get paragraph with text', () => {
  259. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  260. setData( model, '<paragraph>foo</paragraph>' );
  261. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  262. expect( data.get() ).to.equal( '<p>foo</p>' );
  263. expect( data.get( { trim: 'empty' } ) ).to.equal( '<p>foo</p>' );
  264. } );
  265. it( 'should trim empty paragraph by default', () => {
  266. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  267. setData( model, '<paragraph></paragraph>' );
  268. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  269. expect( data.get() ).to.equal( '' );
  270. expect( data.get( { trim: 'empty' } ) ).to.equal( '' );
  271. } );
  272. it( 'should get empty paragraph (with trim=none)', () => {
  273. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  274. setData( model, '<paragraph></paragraph>' );
  275. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  276. expect( data.get( { trim: 'none' } ) ).to.equal( '<p>&nbsp;</p>' );
  277. } );
  278. it( 'should get two paragraphs', () => {
  279. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  280. setData( model, '<paragraph>foo</paragraph><paragraph>bar</paragraph>' );
  281. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  282. expect( data.get() ).to.equal( '<p>foo</p><p>bar</p>' );
  283. expect( data.get( { trim: 'empty' } ) ).to.equal( '<p>foo</p><p>bar</p>' );
  284. } );
  285. it( 'should get text directly in root', () => {
  286. schema.extend( '$text', { allowIn: '$root' } );
  287. setData( model, 'foo' );
  288. expect( data.get() ).to.equal( 'foo' );
  289. expect( data.get( { trim: 'empty' } ) ).to.equal( 'foo' );
  290. } );
  291. it( 'should get paragraphs without bold', () => {
  292. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  293. setData( model, '<paragraph>foo<$text bold="true">bar</$text></paragraph>' );
  294. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  295. expect( data.get() ).to.equal( '<p>foobar</p>' );
  296. expect( data.get( { trim: 'empty' } ) ).to.equal( '<p>foobar</p>' );
  297. } );
  298. it( 'should get paragraphs with bold', () => {
  299. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  300. setData( model, '<paragraph>foo<$text bold="true">bar</$text></paragraph>' );
  301. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  302. downcastHelpers.attributeToElement( { model: 'bold', view: 'strong' } );
  303. expect( data.get() ).to.equal( '<p>foo<strong>bar</strong></p>' );
  304. expect( data.get( { trim: 'empty' } ) ).to.equal( '<p>foo<strong>bar</strong></p>' );
  305. } );
  306. it( 'should get root name as a parameter', () => {
  307. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  308. schema.extend( '$text', { allowIn: '$root' } );
  309. setData( model, '<paragraph>foo</paragraph>', { rootName: 'main' } );
  310. setData( model, 'Bar', { rootName: 'title' } );
  311. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  312. downcastHelpers.attributeToElement( { model: 'bold', view: 'strong' } );
  313. expect( data.get() ).to.equal( '<p>foo</p>' );
  314. expect( data.get( { rootName: 'main' } ) ).to.equal( '<p>foo</p>' );
  315. expect( data.get( { rootName: 'title' } ) ).to.equal( 'Bar' );
  316. } );
  317. it( 'should throw an error when non-existent root is used', () => {
  318. expect( () => {
  319. data.get( { rootName: 'nonexistent' } );
  320. } ).to.throw(
  321. CKEditorError,
  322. 'datacontroller-get-non-existent-root: Attempting to get data from a non-existing root.'
  323. );
  324. } );
  325. } );
  326. describe( 'stringify()', () => {
  327. beforeEach( () => {
  328. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  329. schema.register( 'div' );
  330. schema.extend( '$block', { allowIn: 'div' } );
  331. schema.extend( 'div', { allowIn: '$root' } );
  332. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  333. } );
  334. it( 'should stringify a content of an element', () => {
  335. const modelElement = parseModel( '<div><paragraph>foo</paragraph></div>', schema );
  336. expect( data.stringify( modelElement ) ).to.equal( '<p>foo</p>' );
  337. } );
  338. it( 'should stringify a content of a document fragment', () => {
  339. const modelDocumentFragment = parseModel( '<paragraph>foo</paragraph><paragraph>bar</paragraph>', schema );
  340. expect( data.stringify( modelDocumentFragment ) ).to.equal( '<p>foo</p><p>bar</p>' );
  341. } );
  342. } );
  343. describe( 'toView()', () => {
  344. beforeEach( () => {
  345. schema.register( 'paragraph', { inheritAllFrom: '$block' } );
  346. schema.register( 'div' );
  347. schema.extend( '$block', { allowIn: 'div' } );
  348. schema.extend( 'div', { allowIn: '$root' } );
  349. downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );
  350. } );
  351. it( 'should convert a content of an element', () => {
  352. const modelElement = parseModel( '<div><paragraph>foo</paragraph></div>', schema );
  353. const viewDocumentFragment = data.toView( modelElement );
  354. expect( viewDocumentFragment ).to.be.instanceOf( ViewDocumentFragment );
  355. const viewElement = viewDocumentFragment.getChild( 0 );
  356. expect( viewElement.name ).to.equal( 'p' );
  357. expect( viewElement.childCount ).to.equal( 1 );
  358. expect( viewElement.getChild( 0 ).data ).to.equal( 'foo' );
  359. } );
  360. it( 'should correctly convert document markers #1', () => {
  361. const modelElement = parseModel( '<div><paragraph>foobar</paragraph></div>', schema );
  362. const modelRoot = model.document.getRoot();
  363. downcastHelpers.markerToHighlight( { model: 'marker:a', view: { classes: 'a' } } );
  364. model.change( writer => {
  365. writer.insert( modelElement, modelRoot, 0 );
  366. const range = writer.createRange( writer.createPositionAt( modelRoot, 0 ), writer.createPositionAt( modelRoot, 1 ) );
  367. writer.addMarker( 'marker:a', { range, usingOperation: true } );
  368. } );
  369. const viewDocumentFragment = data.toView( modelElement );
  370. const viewElement = viewDocumentFragment.getChild( 0 );
  371. expect( stringifyView( viewElement ) ).to.equal( '<p><span class="a">foobar</span></p>' );
  372. } );
  373. it( 'should correctly convert document markers #2', () => {
  374. const modelElement = parseModel( '<div><paragraph>foo</paragraph><paragraph>bar</paragraph></div>', schema );
  375. const modelRoot = model.document.getRoot();
  376. downcastHelpers.markerToHighlight( { model: 'marker:a', view: { classes: 'a' } } );
  377. downcastHelpers.markerToHighlight( { model: 'marker:b', view: { classes: 'b' } } );
  378. const modelP1 = modelElement.getChild( 0 );
  379. const modelP2 = modelElement.getChild( 1 );
  380. model.change( writer => {
  381. writer.insert( modelElement, modelRoot, 0 );
  382. const rangeA = writer.createRange( writer.createPositionAt( modelP1, 1 ), writer.createPositionAt( modelP1, 3 ) );
  383. const rangeB = writer.createRange( writer.createPositionAt( modelP2, 0 ), writer.createPositionAt( modelP2, 2 ) );
  384. writer.addMarker( 'marker:a', { range: rangeA, usingOperation: true } );
  385. writer.addMarker( 'marker:b', { range: rangeB, usingOperation: true } );
  386. } );
  387. const viewDocumentFragment = data.toView( modelP1 );
  388. expect( stringifyView( viewDocumentFragment ) ).to.equal( 'f<span class="a">oo</span>' );
  389. } );
  390. it( 'should convert a document fragment', () => {
  391. const modelDocumentFragment = parseModel( '<paragraph>foo</paragraph><paragraph>bar</paragraph>', schema );
  392. const viewDocumentFragment = data.toView( modelDocumentFragment );
  393. expect( viewDocumentFragment ).to.be.instanceOf( ViewDocumentFragment );
  394. expect( viewDocumentFragment ).to.have.property( 'childCount', 2 );
  395. const viewElement = viewDocumentFragment.getChild( 0 );
  396. expect( viewElement.name ).to.equal( 'p' );
  397. expect( viewElement.childCount ).to.equal( 1 );
  398. expect( viewElement.getChild( 0 ).data ).to.equal( 'foo' );
  399. } );
  400. it( 'should keep view-model mapping', () => {
  401. const modelDocumentFragment = parseModel( '<paragraph>foo</paragraph><paragraph>bar</paragraph>', schema );
  402. const viewDocumentFragment = data.toView( modelDocumentFragment );
  403. const firstModelElement = modelDocumentFragment.getChild( 0 );
  404. const firstViewElement = viewDocumentFragment.getChild( 0 );
  405. const modelRange = ModelRange._createOn( firstModelElement );
  406. const viewRange = ViewRange._createOn( firstViewElement );
  407. const mappedModelRange = data.mapper.toModelRange( viewRange );
  408. const mappedViewRange = data.mapper.toViewRange( modelRange );
  409. expect( mappedModelRange ).to.be.instanceOf( ModelRange );
  410. expect( mappedViewRange ).to.be.instanceOf( ViewRange );
  411. expect( mappedModelRange.end.nodeBefore ).to.equal( firstModelElement );
  412. expect( mappedModelRange.end.nodeAfter ).to.equal( modelDocumentFragment.getChild( 1 ) );
  413. expect( mappedViewRange.end.nodeBefore ).to.equal( firstViewElement );
  414. expect( mappedViewRange.end.nodeAfter ).to.equal( viewDocumentFragment.getChild( 1 ) );
  415. } );
  416. } );
  417. describe( 'destroy()', () => {
  418. it( 'should be there for you', () => {
  419. // Should not throw.
  420. data.destroy();
  421. expect( data ).to.respondTo( 'destroy' );
  422. } );
  423. } );
  424. } );