datacontroller.js 21 KB

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