datacontroller.js 20 KB

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