8
0

view-to-dom.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals Range, DocumentFragment, HTMLElement, document, Text */
  6. import ViewText from '../../../src/view/text';
  7. import ViewElement from '../../../src/view/element';
  8. import ViewPosition from '../../../src/view/position';
  9. import ViewContainerElement from '../../../src/view/containerelement';
  10. import ViewAttributeElement from '../../../src/view/attributeelement';
  11. import DomConverter from '../../../src/view/domconverter';
  12. import ViewDocumentFragment from '../../../src/view/documentfragment';
  13. import { INLINE_FILLER, INLINE_FILLER_LENGTH, isBlockFiller } from '../../../src/view/filler';
  14. import { parse } from '../../../src/dev-utils/view';
  15. import createElement from '@ckeditor/ckeditor5-utils/src/dom/createelement';
  16. describe( 'DomConverter', () => {
  17. let converter;
  18. before( () => {
  19. converter = new DomConverter();
  20. } );
  21. describe( 'viewToDom', () => {
  22. it( 'should create tree of DOM elements from view elements', () => {
  23. const viewImg = new ViewElement( 'img' );
  24. const viewText = new ViewText( 'foo' );
  25. const viewP = new ViewElement( 'p' );
  26. viewP.setAttribute( 'class', 'foo' );
  27. viewP.appendChildren( viewImg );
  28. viewP.appendChildren( viewText );
  29. const domImg = document.createElement( 'img' );
  30. converter.bindElements( domImg, viewImg );
  31. const domP = converter.viewToDom( viewP, document );
  32. expect( domP ).to.be.an.instanceof( HTMLElement );
  33. expect( domP.tagName ).to.equal( 'P' );
  34. expect( domP.getAttribute( 'class' ) ).to.equal( 'foo' );
  35. expect( domP.attributes.length ).to.equal( 1 );
  36. expect( domP.childNodes.length ).to.equal( 2 );
  37. expect( domP.childNodes[ 0 ].tagName ).to.equal( 'IMG' );
  38. expect( domP.childNodes[ 1 ].data ).to.equal( 'foo' );
  39. expect( converter.getCorrespondingView( domP ) ).not.to.equal( viewP );
  40. expect( converter.getCorrespondingView( domP.childNodes[ 0 ] ) ).to.equal( viewImg );
  41. } );
  42. it( 'should create tree of DOM elements from view elements and bind elements', () => {
  43. const viewImg = new ViewElement( 'img' );
  44. const viewText = new ViewText( 'foo' );
  45. const viewP = new ViewElement( 'p' );
  46. viewP.setAttribute( 'class', 'foo' );
  47. viewP.appendChildren( viewImg );
  48. viewP.appendChildren( viewText );
  49. const domP = converter.viewToDom( viewP, document, { bind: true } );
  50. expect( domP ).to.be.an.instanceof( HTMLElement );
  51. expect( domP.tagName ).to.equal( 'P' );
  52. expect( domP.getAttribute( 'class' ) ).to.equal( 'foo' );
  53. expect( domP.attributes.length ).to.equal( 1 );
  54. expect( domP.childNodes.length ).to.equal( 2 );
  55. expect( domP.childNodes[ 0 ].tagName ).to.equal( 'IMG' );
  56. expect( domP.childNodes[ 1 ].data ).to.equal( 'foo' );
  57. expect( converter.getCorrespondingView( domP ) ).to.equal( viewP );
  58. expect( converter.getCorrespondingView( domP.childNodes[ 0 ] ) ).to.equal( viewP.getChild( 0 ) );
  59. } );
  60. it( 'should support unicode', () => {
  61. const viewText = new ViewText( 'நிலைக்கு' );
  62. const viewP = new ViewElement( 'p', null, viewText );
  63. const domP = converter.viewToDom( viewP, document, { bind: true } );
  64. expect( domP.childNodes.length ).to.equal( 1 );
  65. expect( domP.childNodes[ 0 ].data ).to.equal( 'நிலைக்கு' );
  66. expect( converter.getCorrespondingView( domP ) ).to.equal( viewP );
  67. expect( converter.getCorrespondingView( domP.childNodes[ 0 ] ) ).to.equal( viewP.getChild( 0 ) );
  68. } );
  69. it( 'should create tree of DOM elements from view element without children', () => {
  70. const viewImg = new ViewElement( 'img' );
  71. const viewText = new ViewText( 'foo' );
  72. const viewP = new ViewElement( 'p' );
  73. viewP.setAttribute( 'class', 'foo' );
  74. viewP.appendChildren( viewImg );
  75. viewP.appendChildren( viewText );
  76. const domImg = document.createElement( 'img' );
  77. converter.bindElements( domImg, viewImg );
  78. const domP = converter.viewToDom( viewP, document, { withChildren: false } );
  79. expect( domP ).to.be.an.instanceof( HTMLElement );
  80. expect( domP.tagName ).to.equal( 'P' );
  81. expect( domP.getAttribute( 'class' ) ).to.equal( 'foo' );
  82. expect( domP.attributes.length ).to.equal( 1 );
  83. expect( domP.childNodes.length ).to.equal( 0 );
  84. expect( converter.getCorrespondingView( domP ) ).not.to.equal( viewP );
  85. } );
  86. it( 'should create DOM document fragment from view document fragment and bind elements', () => {
  87. const viewImg = new ViewElement( 'img' );
  88. const viewText = new ViewText( 'foo' );
  89. const viewFragment = new ViewDocumentFragment();
  90. viewFragment.appendChildren( viewImg );
  91. viewFragment.appendChildren( viewText );
  92. const domFragment = converter.viewToDom( viewFragment, document, { bind: true } );
  93. expect( domFragment ).to.be.an.instanceof( DocumentFragment );
  94. expect( domFragment.childNodes.length ).to.equal( 2 );
  95. expect( domFragment.childNodes[ 0 ].tagName ).to.equal( 'IMG' );
  96. expect( domFragment.childNodes[ 1 ].data ).to.equal( 'foo' );
  97. expect( converter.getCorrespondingView( domFragment ) ).to.equal( viewFragment );
  98. expect( converter.getCorrespondingView( domFragment.childNodes[ 0 ] ) ).to.equal( viewFragment.getChild( 0 ) );
  99. } );
  100. it( 'should create DOM document fragment from view document without children', () => {
  101. const viewImg = new ViewElement( 'img' );
  102. const viewText = new ViewText( 'foo' );
  103. const viewFragment = new ViewDocumentFragment();
  104. viewFragment.appendChildren( viewImg );
  105. viewFragment.appendChildren( viewText );
  106. const domImg = document.createElement( 'img' );
  107. converter.bindElements( domImg, viewImg );
  108. const domFragment = converter.viewToDom( viewFragment, document, { withChildren: false } );
  109. expect( domFragment ).to.be.an.instanceof( DocumentFragment );
  110. expect( domFragment.childNodes.length ).to.equal( 0 );
  111. expect( converter.getCorrespondingView( domFragment ) ).not.to.equal( viewFragment );
  112. } );
  113. it( 'should return already bind document fragment', () => {
  114. const domFragment = document.createDocumentFragment();
  115. const viewFragment = new ViewDocumentFragment();
  116. converter.bindDocumentFragments( domFragment, viewFragment );
  117. const domFragment2 = converter.viewToDom( viewFragment, document );
  118. expect( domFragment2 ).to.equal( domFragment );
  119. } );
  120. it( 'should create DOM text node from view text node', () => {
  121. const viewTextNode = new ViewText( 'foo' );
  122. const domTextNode = converter.viewToDom( viewTextNode, document );
  123. expect( domTextNode ).to.be.instanceof( Text );
  124. expect( domTextNode.data ).to.equal( 'foo' );
  125. } );
  126. describe( 'it should convert spaces to  ', () => {
  127. it( 'at the beginning of each container element', () => {
  128. const viewDiv = new ViewContainerElement( 'div', null, [
  129. new ViewContainerElement( 'p', null, new ViewText( ' foo' ) ),
  130. new ViewContainerElement( 'p', null, new ViewText( 'bar' ) ),
  131. new ViewContainerElement( 'p', null, new ViewText( ' xxx' ) )
  132. ] );
  133. const domDiv = converter.viewToDom( viewDiv, document );
  134. expect( domDiv.innerHTML ).to.equal( '<p>&nbsp;foo</p><p>bar</p><p>&nbsp;xxx</p>' );
  135. } );
  136. it( 'at the end of each container element', () => {
  137. const viewDiv = new ViewContainerElement( 'div', null, [
  138. new ViewContainerElement( 'p', null, new ViewText( 'foo ' ) ),
  139. new ViewContainerElement( 'p', null, new ViewText( 'bar' ) ),
  140. new ViewContainerElement( 'p', null, new ViewText( 'xxx ' ) )
  141. ] );
  142. const domDiv = converter.viewToDom( viewDiv, document );
  143. expect( domDiv.innerHTML ).to.equal( '<p>foo&nbsp;</p><p>bar</p><p>xxx&nbsp;</p>' );
  144. } );
  145. it( 'when there are multiple spaces next to each other or between attribute elements', () => {
  146. const viewDiv = new ViewContainerElement( 'div', null, [
  147. new ViewText( 'x x x x ' ),
  148. new ViewAttributeElement( 'b', null, new ViewText( ' x ' ) ),
  149. new ViewAttributeElement( 'i', null,
  150. new ViewAttributeElement( 'b', null,
  151. new ViewAttributeElement( 'u' , null, new ViewText( ' x' ) )
  152. )
  153. )
  154. ] );
  155. const domDiv = converter.viewToDom( viewDiv, document );
  156. expect( domDiv.innerHTML ).to.equal( 'x &nbsp;x &nbsp; x x <b>&nbsp;x </b><i><b><u>&nbsp;x</u></b></i>' );
  157. } );
  158. it( 'all together', () => {
  159. const viewDiv = new ViewContainerElement( 'div', null, [
  160. new ViewContainerElement( 'p', null, [
  161. new ViewText( ' x x x x ' ),
  162. new ViewAttributeElement( 'b', null, new ViewText( ' x ' ) ),
  163. new ViewAttributeElement( 'i', null,
  164. new ViewAttributeElement( 'b', null,
  165. new ViewAttributeElement( 'u' , null, new ViewText( ' x ' ) )
  166. )
  167. )
  168. ] ),
  169. new ViewContainerElement( 'p', null, new ViewText( ' x ' ) )
  170. ] );
  171. const domDiv = converter.viewToDom( viewDiv, document );
  172. expect( domDiv.innerHTML ).to.equal(
  173. '<p>&nbsp;x &nbsp;x &nbsp; x x <b>&nbsp;x </b><i><b><u>&nbsp;x&nbsp;</u></b></i></p><p>&nbsp; x &nbsp;</p>'
  174. );
  175. } );
  176. function test( inputTexts, output ) {
  177. if ( typeof inputTexts == 'string' ) {
  178. inputTexts = [ inputTexts ];
  179. }
  180. it( 'spaces in a text node: ' + inputTexts.join( '|' ) + ' -> ' + output, () => {
  181. const viewElement = new ViewContainerElement( 'p' );
  182. for ( let text of inputTexts ) {
  183. viewElement.appendChildren( new ViewText( text.replace( /_/g, '\u00A0' ) ) );
  184. }
  185. const domElement = converter.viewToDom( viewElement, document );
  186. const data = domElement.innerHTML.replace( /&nbsp;/g, '_' );
  187. expect( data ).to.equal( output );
  188. } );
  189. }
  190. // At the beginning.
  191. test( ' x', '_x' );
  192. test( ' x', '_ x' );
  193. test( ' x', '_ _x' );
  194. test( ' x', '_ _ x' );
  195. // At the end.
  196. test( 'x ', 'x_' );
  197. test( 'x ', 'x _' );
  198. test( 'x ', 'x_ _' );
  199. test( 'x ', 'x _ _' );
  200. // In the middle.
  201. test( 'x x', 'x x' );
  202. test( 'x x', 'x _x' );
  203. test( 'x x', 'x _ x' );
  204. test( 'x x', 'x _ _x' );
  205. // Complex.
  206. test( ' x ', '_x_' );
  207. test( ' x x ', '_ x _x _' );
  208. test( ' x x ', '_ _x x _' );
  209. test( ' x x ', '_ _x x_ _' );
  210. test( ' x x ', '_ _x _ _x_' );
  211. test( ' ', '_' );
  212. // With hard &nbsp;
  213. test( '_x', '_x' );
  214. test( ' _x', '__x' );
  215. test( ' _x', '_ _x' );
  216. test( ' __x', '___x' );
  217. test( '___x', '___x' );
  218. test( '_ _x', '_ _x' );
  219. test( ' _ x', '__ x' );
  220. test( ' _x', '_ _x' );
  221. test( 'x_', 'x_' );
  222. test( 'x_ ', 'x__' );
  223. test( 'x_ ', 'x_ _' );
  224. test( 'x__ ', 'x___' );
  225. test( 'x___', 'x___' );
  226. test( 'x_ _', 'x_ _' );
  227. test( 'x _ ', 'x __' );
  228. test( 'x _', 'x __' );
  229. test( 'x_x', 'x_x' );
  230. test( 'x___x', 'x___x' );
  231. test( 'x__ x', 'x__ x' );
  232. test( 'x_ x', 'x_ _x' );
  233. test( 'x _x', 'x __x' );
  234. test( 'x __x', 'x __x' );
  235. test( 'x _ x', 'x _ x' );
  236. test( 'x _ x', 'x __ _x' );
  237. // Two text nodes.
  238. test( [ 'x', 'y' ], 'xy' );
  239. test( [ 'x ', 'y' ], 'x y' );
  240. test( [ 'x ', 'y' ], 'x _y' );
  241. test( [ 'x ', 'y' ], 'x _ y' );
  242. test( [ 'x ', 'y' ], 'x _ _y' );
  243. test( [ 'x', ' y' ], 'x y' );
  244. test( [ 'x ', ' y' ], 'x _y' );
  245. test( [ 'x ', ' y' ], 'x_ _y' );
  246. test( [ 'x ', ' y' ], 'x _ _y' );
  247. test( [ 'x ', ' y' ], 'x_ _ _y' );
  248. test( [ 'x', '_y' ], 'x_y' );
  249. test( [ 'x ', '_y' ], 'x _y' );
  250. test( [ 'x ', '_y' ], 'x_ _y' );
  251. test( [ 'x ', '_y' ], 'x _ _y' );
  252. test( [ 'x ', '_y' ], 'x_ _ _y' );
  253. test( [ 'x', ' y' ], 'x _y' );
  254. test( [ 'x ', ' y' ], 'x _ y' );
  255. test( [ 'x ', ' y' ], 'x_ _ y' );
  256. test( [ 'x ', ' y' ], 'x _ _ y' );
  257. test( [ 'x ', ' y' ], 'x_ _ _ y' );
  258. test( [ 'x', ' y' ], 'x _ y' );
  259. test( [ 'x ', ' y' ], 'x _ _y' );
  260. test( [ 'x ', ' y' ], 'x_ _ _y' );
  261. test( [ 'x ', ' y' ], 'x _ _ _y' );
  262. test( [ 'x ', ' y' ], 'x_ _ _ _y' );
  263. it( 'not in preformatted blocks', () => {
  264. const viewDiv = new ViewContainerElement( 'pre', null, new ViewText( ' foo ' ) );
  265. const domDiv = converter.viewToDom( viewDiv, document );
  266. expect( domDiv.innerHTML ).to.equal( ' foo ' );
  267. } );
  268. } );
  269. } );
  270. describe( 'viewChildrenToDom', () => {
  271. it( 'should convert children', () => {
  272. const viewP = parse( '<container:p>foo<attribute:b>bar</attribute:b></container:p>' );
  273. const domChildren = Array.from( converter.viewChildrenToDom( viewP, document ) );
  274. expect( domChildren.length ).to.equal( 2 );
  275. expect( domChildren[ 0 ].data ).to.equal( 'foo' );
  276. expect( domChildren[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
  277. expect( domChildren[ 1 ].childNodes.length ).to.equal( 1 );
  278. } );
  279. it( 'should add filler', () => {
  280. const viewP = parse( '<container:p></container:p>' );
  281. const domChildren = Array.from( converter.viewChildrenToDom( viewP, document ) );
  282. expect( domChildren.length ).to.equal( 1 );
  283. expect( isBlockFiller( domChildren[ 0 ], converter.blockFiller ) ).to.be.true;
  284. } );
  285. it( 'should add filler according to fillerPositionOffset', () => {
  286. const viewP = parse( '<container:p>foo</container:p>' );
  287. viewP.getFillerOffset = () => 0;
  288. const domChildren = Array.from( converter.viewChildrenToDom( viewP, document ) );
  289. expect( domChildren.length ).to.equal( 2 );
  290. expect( isBlockFiller( domChildren[ 0 ], converter.blockFiller ) ).to.be.true;
  291. expect( domChildren[ 1 ].data ).to.equal( 'foo' );
  292. } );
  293. it( 'should pass options', () => {
  294. const viewP = parse( '<container:p>foo<attribute:b>bar</attribute:b></container:p>' );
  295. const domChildren = Array.from( converter.viewChildrenToDom( viewP, document, { withChildren: false } ) );
  296. expect( domChildren.length ).to.equal( 2 );
  297. expect( domChildren[ 0 ].data ).to.equal( 'foo' );
  298. expect( domChildren[ 1 ].tagName.toLowerCase() ).to.equal( 'b' );
  299. expect( domChildren[ 1 ].childNodes.length ).to.equal( 0 );
  300. } );
  301. } );
  302. describe( 'viewPositionToDom', () => {
  303. it( 'should convert the position in the text', () => {
  304. const domFoo = document.createTextNode( 'foo' );
  305. const domP = createElement( document, 'p', null, domFoo );
  306. const { view: viewP, selection } = parse( '<container:p>fo{}o</container:p>' );
  307. converter.bindElements( domP, viewP );
  308. const viewPosition = selection.getFirstPosition();
  309. const domPosition = converter.viewPositionToDom( viewPosition );
  310. expect( domPosition.offset ).to.equal( 2 );
  311. expect( domPosition.parent ).to.equal( domFoo );
  312. } );
  313. it( 'should support unicode', () => {
  314. const domText = document.createTextNode( 'நிலைக்கு' );
  315. const domP = createElement( document, 'p', null, domText );
  316. const { view: viewP, selection } = parse( '<container:p>நிலை{}க்கு</container:p>' );
  317. converter.bindElements( domP, viewP );
  318. const viewPosition = selection.getFirstPosition();
  319. const domPosition = converter.viewPositionToDom( viewPosition );
  320. expect( domPosition.offset ).to.equal( 4 );
  321. expect( domPosition.parent ).to.equal( domText );
  322. } );
  323. it( 'should convert the position in the empty element', () => {
  324. const domP = createElement( document, 'p' );
  325. const { view: viewP, selection } = parse( '<container:p>[]</container:p>' );
  326. converter.bindElements( domP, viewP );
  327. const viewPosition = selection.getFirstPosition();
  328. const domPosition = converter.viewPositionToDom( viewPosition );
  329. expect( domPosition.offset ).to.equal( 0 );
  330. expect( domPosition.parent ).to.equal( domP );
  331. } );
  332. it( 'should convert the position in the non-empty element', () => {
  333. const domB = createElement( document, 'b', null, 'foo' );
  334. const domP = createElement( document, 'p', null, domB );
  335. const { view: viewP, selection } = parse( '<container:p><attribute:b>foo</attribute:b>[]</container:p>' );
  336. converter.bindElements( domP, viewP );
  337. converter.bindElements( domB, viewP.getChild( 0 ) );
  338. const viewPosition = selection.getFirstPosition();
  339. const domPosition = converter.viewPositionToDom( viewPosition );
  340. expect( domPosition.offset ).to.equal( 1 );
  341. expect( domPosition.parent ).to.equal( domP );
  342. } );
  343. it( 'should convert the position after text', () => {
  344. const domP = createElement( document, 'p', null, 'foo' );
  345. const { view: viewP, selection } = parse( '<container:p>foo[]</container:p>' );
  346. converter.bindElements( domP, viewP );
  347. const viewPosition = selection.getFirstPosition();
  348. const domPosition = converter.viewPositionToDom( viewPosition );
  349. expect( domPosition.offset ).to.equal( 1 );
  350. expect( domPosition.parent ).to.equal( domP );
  351. } );
  352. it( 'should convert the position before text', () => {
  353. const domP = createElement( document, 'p', null, 'foo' );
  354. const { view: viewP, selection } = parse( '<container:p>[]foo</container:p>' );
  355. converter.bindElements( domP, viewP );
  356. const viewPosition = selection.getFirstPosition();
  357. const domPosition = converter.viewPositionToDom( viewPosition );
  358. expect( domPosition.offset ).to.equal( 0 );
  359. expect( domPosition.parent ).to.equal( domP );
  360. } );
  361. it( 'should update offset if DOM text node starts with inline filler', () => {
  362. const domFoo = document.createTextNode( INLINE_FILLER + 'foo' );
  363. const domP = createElement( document, 'p', null, domFoo );
  364. const { view: viewP, selection } = parse( '<container:p>fo{}o</container:p>' );
  365. converter.bindElements( domP, viewP );
  366. const viewPosition = selection.getFirstPosition();
  367. const domPosition = converter.viewPositionToDom( viewPosition );
  368. expect( domPosition.offset ).to.equal( INLINE_FILLER_LENGTH + 2 );
  369. expect( domPosition.parent ).to.equal( domFoo );
  370. } );
  371. it( 'should move the position to the text node if the position is where inline filler is', () => {
  372. const domFiller = document.createTextNode( INLINE_FILLER );
  373. const domP = createElement( document, 'p', null, domFiller );
  374. const { view: viewP, selection } = parse( '<container:p>[]</container:p>' );
  375. converter.bindElements( domP, viewP );
  376. const viewPosition = selection.getFirstPosition();
  377. const domPosition = converter.viewPositionToDom( viewPosition );
  378. expect( domPosition.offset ).to.equal( INLINE_FILLER_LENGTH );
  379. expect( domPosition.parent ).to.equal( domFiller );
  380. } );
  381. it( 'should return null if view position is after a view element that has not been rendered to DOM', () => {
  382. const domP = createElement( document, 'p', null );
  383. const { view: viewP, selection } = parse( '<container:p><attribute:b>foo</attribute:b>[]</container:p>' );
  384. converter.bindElements( domP, viewP );
  385. const viewPosition = selection.getFirstPosition();
  386. const domPosition = converter.viewPositionToDom( viewPosition );
  387. expect( domPosition ).to.equal( null );
  388. } );
  389. it( 'should return null if view position is in a view text node that has not been rendered to DOM', () => {
  390. const viewText = new ViewText( 'foo' );
  391. const viewPosition = new ViewPosition( viewText, 1 );
  392. const domPosition = converter.viewPositionToDom( viewPosition );
  393. expect( domPosition ).to.equal( null );
  394. } );
  395. it( 'should return null if view position is in a view element that has not been rendered to DOM', () => {
  396. const viewElement = new ViewContainerElement( 'div' );
  397. const viewPosition = new ViewPosition( viewElement, 0 );
  398. const domPosition = converter.viewPositionToDom( viewPosition );
  399. expect( domPosition ).to.equal( null );
  400. } );
  401. } );
  402. describe( 'viewRangeToDom', () => {
  403. it( 'should convert view range to DOM range', () => {
  404. const domFoo = document.createTextNode( 'foo' );
  405. const domP = createElement( document, 'p', null, domFoo );
  406. const { view: viewP, selection } = parse( '<container:p>fo{o]</container:p>' );
  407. converter.bindElements( domP, viewP );
  408. const viewRange = selection.getFirstRange();
  409. const domRange = converter.viewRangeToDom( viewRange );
  410. expect( domRange ).to.be.instanceof( Range );
  411. expect( domRange.startContainer ).to.equal( domFoo );
  412. expect( domRange.startOffset ).to.equal( 2 );
  413. expect( domRange.endContainer ).to.equal( domP );
  414. expect( domRange.endOffset ).to.equal( 1 );
  415. } );
  416. } );
  417. } );