position.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Position from '../../src/view/position';
  6. import Node from '../../src/view/node';
  7. import Element from '../../src/view/element';
  8. import DocumentFragment from '../../src/view/documentfragment';
  9. import EditableElement from '../../src/view/editableelement';
  10. import Document from '../../src/view/document';
  11. import Text from '../../src/view/text';
  12. import TextProxy from '../../src/view/textproxy';
  13. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  14. import { parse, stringify } from '../../src/dev-utils/view';
  15. describe( 'Position', () => {
  16. const parentMock = {};
  17. describe( 'constructor()', () => {
  18. it( 'should create element without attributes', () => {
  19. const elem = new Position( parentMock, 5 );
  20. expect( elem ).to.have.property( 'parent' ).that.equals( parentMock );
  21. expect( elem ).to.have.property( 'offset' ).that.equals( 5 );
  22. } );
  23. } );
  24. describe( 'nodeBefore', () => {
  25. it( 'should equal to node that is before position', () => {
  26. const b1 = new Element( 'b' );
  27. const el = new Element( 'p', null, [ b1 ] );
  28. const position = new Position( el, 1 );
  29. expect( position.nodeBefore ).to.equal( b1 );
  30. } );
  31. it( 'should equal null if there is no node before', () => {
  32. const b1 = new Element( 'b' );
  33. const el = new Element( 'p', null, [ b1 ] );
  34. const position = new Position( el, 0 );
  35. expect( position.nodeBefore ).to.be.null;
  36. } );
  37. it( 'should equal null if position is located inside text node', () => {
  38. const text = new Text( 'foobar' );
  39. const position = new Position( text, 3 );
  40. expect( position.nodeBefore ).to.be.null;
  41. } );
  42. } );
  43. describe( 'nodeAfter', () => {
  44. it( 'should equal to node that is after position', () => {
  45. const b1 = new Element( 'b' );
  46. const el = new Element( 'p', null, [ b1 ] );
  47. const position = new Position( el, 0 );
  48. expect( position.nodeAfter ).to.equal( b1 );
  49. } );
  50. it( 'should equal null if there is no node before', () => {
  51. const b1 = new Element( 'b' );
  52. const el = new Element( 'p', null, [ b1 ] );
  53. const position = new Position( el, 1 );
  54. expect( position.nodeAfter ).to.be.null;
  55. } );
  56. it( 'should equal null if position is located inside text node', () => {
  57. const text = new Text( 'foobar' );
  58. const position = new Position( text, 3 );
  59. expect( position.nodeAfter ).to.be.null;
  60. } );
  61. } );
  62. describe( 'getShiftedBy', () => {
  63. it( 'returns new instance with shifted offset', () => {
  64. const position = new Position( parentMock, 10 );
  65. const shifted = position.getShiftedBy( 12 );
  66. expect( shifted.offset ).to.equal( 22 );
  67. } );
  68. it( 'accepts negative values', () => {
  69. const position = new Position( parentMock, 10 );
  70. const shifted = position.getShiftedBy( -5 );
  71. expect( shifted.offset ).to.equal( 5 );
  72. } );
  73. it( 'prevents offset to be a negative value', () => {
  74. const position = new Position( parentMock, 10 );
  75. const shifted = position.getShiftedBy( -20 );
  76. expect( shifted.offset ).to.equal( 0 );
  77. } );
  78. } );
  79. describe( 'getLastMatchingPosition', () => {
  80. it( 'should skip forward', () => {
  81. const { view, selection } = parse( '<p><b>{}foo</b></p>' );
  82. let position = selection.getFirstPosition();
  83. position = position.getLastMatchingPosition( value => value.type == 'text' );
  84. expect( stringify( view, position ) ).to.equal( '<p><b>foo[]</b></p>' );
  85. } );
  86. it( 'should skip backward', () => {
  87. const { view, selection } = parse( '<p><b>foo{}</b></p>' );
  88. let position = selection.getFirstPosition();
  89. position = position.getLastMatchingPosition( value => value.type == 'text', { direction: 'backward' } );
  90. expect( stringify( view, position ) ).to.equal( '<p><b>[]foo</b></p>' );
  91. } );
  92. } );
  93. describe( 'getRoot', () => {
  94. it( 'should return it\'s parent root', () => {
  95. const foo = new Text( 'foo' );
  96. const docFrag = new DocumentFragment( foo );
  97. expect( new Position( foo, 1 ).root ).to.equal( docFrag );
  98. const bar = new Text( 'bar' );
  99. const p = new Element( 'p', null, bar );
  100. expect( new Position( bar, 2 ).root ).to.equal( p );
  101. expect( new Position( p, 0 ).root ).to.equal( p );
  102. } );
  103. } );
  104. describe( 'getAncestors', () => {
  105. it( 'should return it\'s parent and all it\'s ancestors', () => {
  106. const foo = new Text( 'foo' );
  107. const p = new Element( 'p', null, foo );
  108. const div = new Element( 'div', null, p );
  109. const docFrag = new DocumentFragment( div );
  110. expect( new Position( foo, 1 ).getAncestors() ).to.deep.equal( [ docFrag, div, p, foo ] );
  111. } );
  112. it( 'should return DocumentFragment if position is directly in document fragment', () => {
  113. const docFrag = new DocumentFragment();
  114. expect( new Position( docFrag, 0 ).getAncestors() ).to.deep.equal( [ docFrag ] );
  115. } );
  116. } );
  117. describe( 'createAt', () => {
  118. it( 'should throw if no offset is passed', () => {
  119. const element = new Element( 'p' );
  120. expect( () => Position.createAt( element ) ).to.throw( CKEditorError, /view-position-createAt-offset-required/ );
  121. } );
  122. it( 'should create positions from positions', () => {
  123. const spy = sinon.spy( Position, 'createFromPosition' );
  124. const p = new Element( 'p' );
  125. const position = new Position( p, 0 );
  126. const created = Position.createAt( position, 0 );
  127. expect( created.isEqual( position ) ).to.be.true;
  128. expect( spy.calledOnce ).to.be.true;
  129. } );
  130. it( 'should create positions from node and offset', () => {
  131. const foo = new Text( 'foo' );
  132. const p = new Element( 'p', null, foo );
  133. expect( Position.createAt( foo, 0 ).parent ).to.equal( foo );
  134. expect( Position.createAt( foo, 0 ).offset ).to.equal( 0 );
  135. expect( Position.createAt( foo, 2 ).parent ).to.equal( foo );
  136. expect( Position.createAt( foo, 2 ).offset ).to.equal( 2 );
  137. expect( Position.createAt( p, 1 ).parent ).to.equal( p );
  138. expect( Position.createAt( p, 1 ).offset ).to.equal( 1 );
  139. } );
  140. it( 'should create positions from node and flag', () => {
  141. const foo = new Text( 'foo' );
  142. const p = new Element( 'p', null, foo );
  143. const fooEnd = Position.createAt( foo, 'end' );
  144. const fooBefore = Position.createAt( foo, 'before' );
  145. const fooAfter = Position.createAt( foo, 'after' );
  146. const pEnd = Position.createAt( p, 'end' );
  147. // pBefore and pAfter would throw.
  148. expect( fooEnd.parent ).to.equal( foo );
  149. expect( fooEnd.offset ).to.equal( 3 );
  150. expect( fooBefore.parent ).to.equal( p );
  151. expect( fooBefore.offset ).to.equal( 0 );
  152. expect( fooAfter.parent ).to.equal( p );
  153. expect( fooAfter.offset ).to.equal( 1 );
  154. expect( pEnd.parent ).to.equal( p );
  155. expect( pEnd.offset ).to.equal( 1 );
  156. } );
  157. it( 'should create positions in document fragment', () => {
  158. const foo = new Text( 'foo' );
  159. const docFrag = new DocumentFragment( [ foo ] );
  160. const pStart = Position.createAt( docFrag, 0 );
  161. const pEnd = Position.createAt( docFrag, 'end' );
  162. expect( pStart.parent ).to.equal( docFrag );
  163. expect( pStart.offset ).to.equal( 0 );
  164. expect( pEnd.parent ).to.equal( docFrag );
  165. expect( pEnd.offset ).to.equal( 1 );
  166. } );
  167. } );
  168. describe( 'createFromPosition', () => {
  169. it( 'creates new Position with same parent and offset', () => {
  170. const offset = 50;
  171. const position = new Position( parentMock, offset );
  172. const newPosition = Position.createFromPosition( position );
  173. expect( position ).to.not.equal( newPosition );
  174. expect( position.offset ).to.equal( offset );
  175. expect( position.parent ).to.equal( parentMock );
  176. } );
  177. } );
  178. describe( 'isEqual', () => {
  179. it( 'should return true for same object', () => {
  180. const position = new Position( {}, 12 );
  181. expect( position.isEqual( position ) ).to.be.true;
  182. } );
  183. it( 'should return true for positions with same parent and offset', () => {
  184. const parentMock = {};
  185. const position1 = new Position( parentMock, 12 );
  186. const position2 = new Position( parentMock, 12 );
  187. expect( position1.isEqual( position2 ) ).to.be.true;
  188. } );
  189. it( 'should return false for positions with different parents', () => {
  190. const position1 = new Position( {}, 12 );
  191. const position2 = new Position( {}, 12 );
  192. expect( position1.isEqual( position2 ) ).to.be.false;
  193. } );
  194. it( 'should return false for positions with different positions', () => {
  195. const parentMock = {};
  196. const position1 = new Position( parentMock, 12 );
  197. const position2 = new Position( parentMock, 2 );
  198. expect( position1.isEqual( position2 ) ).to.be.false;
  199. } );
  200. } );
  201. describe( 'isBefore', () => {
  202. it( 'should return false for same positions', () => {
  203. const node = new Node();
  204. const position1 = new Position( node, 10 );
  205. const position2 = new Position( node, 10 );
  206. expect( position1.isBefore( position1 ) ).to.be.false;
  207. expect( position1.isBefore( position2 ) ).to.be.false;
  208. expect( position2.isBefore( position1 ) ).to.be.false;
  209. } );
  210. it( 'should return false if no common ancestor is found', () => {
  211. const t1 = new Text( 'foo' );
  212. const t2 = new Text( 'bar' );
  213. const e1 = new Element( 'p', null, [ t1 ] );
  214. const e2 = new Element( 'p', null, [ t2 ] );
  215. const position1 = new Position( e1, 0 );
  216. const position2 = new Position( e2, 1 );
  217. expect( position1.isBefore( position2 ) );
  218. expect( position2.isBefore( position1 ) );
  219. } );
  220. it( 'should return true if position is before in same node', () => {
  221. const node = new Node();
  222. const p1 = new Position( node, 10 );
  223. const p2 = new Position( node, 5 );
  224. expect( p2.isBefore( p1 ) ).to.be.true;
  225. expect( p1.isBefore( p2 ) ).to.be.false;
  226. } );
  227. it( 'should compare positions that have common parent', () => {
  228. const t1 = new Text( 'foo' );
  229. const t2 = new Text( 'bar' );
  230. const root = new Element( 'p', null, [ t1, t2 ] );
  231. const position1 = new Position( t1, 2 );
  232. const position2 = new Position( t2, 0 );
  233. const position3 = new Position( root, 0 );
  234. const position4 = new Position( root, 2 );
  235. const position5 = new Position( t1, 0 );
  236. const position6 = new Position( root, 1 );
  237. expect( position1.isBefore( position2 ) ).to.be.true;
  238. expect( position2.isBefore( position1 ) ).to.be.false;
  239. expect( position3.isBefore( position1 ) ).to.be.true;
  240. expect( position3.isBefore( position2 ) ).to.be.true;
  241. expect( position1.isBefore( position3 ) ).to.be.false;
  242. expect( position2.isBefore( position3 ) ).to.be.false;
  243. expect( position4.isBefore( position1 ) ).to.be.false;
  244. expect( position4.isBefore( position3 ) ).to.be.false;
  245. expect( position3.isBefore( position4 ) ).to.be.true;
  246. expect( position3.isBefore( position5 ) ).to.be.true;
  247. expect( position6.isBefore( position2 ) ).to.be.true;
  248. expect( position1.isBefore( position6 ) ).to.be.true;
  249. } );
  250. } );
  251. describe( 'isAfter', () => {
  252. it( 'should return false for same positions', () => {
  253. const node = new Node();
  254. const position1 = new Position( node, 10 );
  255. const position2 = new Position( node, 10 );
  256. expect( position1.isAfter( position1 ) ).to.be.false;
  257. expect( position1.isAfter( position2 ) ).to.be.false;
  258. expect( position2.isAfter( position1 ) ).to.be.false;
  259. } );
  260. it( 'should return false if no common ancestor is found', () => {
  261. const t1 = new Text( 'foo' );
  262. const t2 = new Text( 'bar' );
  263. const e1 = new Element( 'p', null, [ t1 ] );
  264. const e2 = new Element( 'p', null, [ t2 ] );
  265. const position1 = new Position( e1, 0 );
  266. const position2 = new Position( e2, 1 );
  267. expect( position1.isAfter( position2 ) );
  268. expect( position2.isAfter( position1 ) );
  269. } );
  270. it( 'should return true if position is after in same node', () => {
  271. const node = new Node();
  272. const p1 = new Position( node, 10 );
  273. const p2 = new Position( node, 5 );
  274. expect( p2.isAfter( p1 ) ).to.be.false;
  275. expect( p1.isAfter( p2 ) ).to.be.true;
  276. } );
  277. it( 'should compare positions that have common parent', () => {
  278. const t1 = new Text( 'foo' );
  279. const t2 = new Text( 'bar' );
  280. const root = new Element( 'p', null, [ t1, t2 ] );
  281. const position1 = new Position( t1, 2 );
  282. const position2 = new Position( t2, 0 );
  283. const position3 = new Position( root, 0 );
  284. const position4 = new Position( root, 2 );
  285. const position5 = new Position( t1, 0 );
  286. const position6 = new Position( root, 1 );
  287. expect( position1.isAfter( position2 ) ).to.be.false;
  288. expect( position2.isAfter( position1 ) ).to.be.true;
  289. expect( position3.isAfter( position1 ) ).to.be.false;
  290. expect( position3.isAfter( position2 ) ).to.be.false;
  291. expect( position1.isAfter( position3 ) ).to.be.true;
  292. expect( position2.isAfter( position3 ) ).to.be.true;
  293. expect( position4.isAfter( position1 ) ).to.be.true;
  294. expect( position4.isAfter( position3 ) ).to.be.true;
  295. expect( position3.isAfter( position4 ) ).to.be.false;
  296. expect( position5.isAfter( position3 ) ).to.be.true;
  297. expect( position2.isAfter( position6 ) ).to.be.true;
  298. } );
  299. } );
  300. describe( 'isAtStart', () => {
  301. it( 'should return true if it is at the start of it\'s parent', () => {
  302. const foo = new Text( 'foo' );
  303. const position = new Position( foo, 0 );
  304. expect( position.isAtStart ).to.be.true;
  305. } );
  306. it( 'should return false if it is not at the start of it\'s parent', () => {
  307. const foo = new Text( 'foo' );
  308. const position = new Position( foo, 1 );
  309. expect( position.isAtStart ).to.be.false;
  310. } );
  311. } );
  312. describe( 'isAtEnd', () => {
  313. it( 'should return true if it is at the end of it\'s parent', () => {
  314. const foo = new Text( 'foo' );
  315. const p = new Element( 'p', null, foo );
  316. expect( new Position( foo, 3 ).isAtEnd ).to.be.true;
  317. expect( new Position( p, 1 ).isAtEnd ).to.be.true;
  318. } );
  319. it( 'should return false if it is not at the end of it\'s parent', () => {
  320. const foo = new Text( 'foo' );
  321. const p = new Element( 'p', null, foo );
  322. expect( new Position( foo, 2 ).isAtEnd ).to.be.false;
  323. expect( new Position( p, 0 ).isAtEnd ).to.be.false;
  324. } );
  325. } );
  326. describe( 'compareWith', () => {
  327. it( 'should return same if positions are same', () => {
  328. const root = new Element();
  329. const position = new Position( root, 0 );
  330. const compared = new Position( root, 0 );
  331. expect( position.compareWith( compared ) ).to.equal( 'same' );
  332. } );
  333. it( 'should return before if the position is before compared one', () => {
  334. const root = new Element();
  335. const position = new Position( root, 0 );
  336. const compared = new Position( root, 1 );
  337. expect( position.compareWith( compared ) ).to.equal( 'before' );
  338. } );
  339. it( 'should return after if the position is after compared one', () => {
  340. const root = new Element();
  341. const position = new Position( root, 4 );
  342. const compared = new Position( root, 1 );
  343. expect( position.compareWith( compared ) ).to.equal( 'after' );
  344. } );
  345. it( 'should return different if positions are in different roots', () => {
  346. const root1 = new Element();
  347. const root2 = new Element();
  348. const position = new Position( root1, 4 );
  349. const compared = new Position( root2, 1 );
  350. expect( position.compareWith( compared ) ).to.equal( 'different' );
  351. } );
  352. it( 'should return correct results if position is in document fragment', () => {
  353. const node = new Element( 'name' );
  354. const docFrag = new DocumentFragment( [ node ] );
  355. const position = new Position( docFrag, 0 );
  356. const compared = new Position( docFrag, 1 );
  357. const posInNode = new Position( node, 0 );
  358. expect( position.compareWith( compared ) ).to.equal( 'before' );
  359. expect( compared.compareWith( position ) ).to.equal( 'after' );
  360. expect( compared.compareWith( compared ) ).to.equal( 'same' );
  361. expect( position.compareWith( posInNode ) ).to.equal( 'before' );
  362. expect( compared.compareWith( posInNode ) ).to.equal( 'after' );
  363. } );
  364. } );
  365. describe( 'createBefore', () => {
  366. it( 'should throw error if one try to create positions before root', () => {
  367. expect( () => {
  368. Position.createBefore( parse( '<p></p>' ) );
  369. } ).to.throw( CKEditorError, /view-position-before-root/ );
  370. } );
  371. it( 'should create positions before `Node`', () => {
  372. const { selection } = parse( '<p>[]<b></b></p>' );
  373. const position = selection.getFirstPosition();
  374. const nodeAfter = position.nodeAfter;
  375. expect( Position.createBefore( nodeAfter ).isEqual( position ) ).to.be.true;
  376. } );
  377. it( 'should create positions before `TextProxy`', () => {
  378. const text = new Text( 'abc' );
  379. const textProxy = new TextProxy( text, 1, 1 );
  380. const position = new Position( text, 1 );
  381. expect( Position.createBefore( textProxy ) ).deep.equal( position );
  382. } );
  383. } );
  384. describe( 'createAfter', () => {
  385. it( 'should throw error if one try to create positions after root', () => {
  386. expect( () => {
  387. Position.createAfter( parse( '<p></p>' ) );
  388. } ).to.throw( CKEditorError, /view-position-after-root/ );
  389. } );
  390. it( 'should create positions after `Node`', () => {
  391. const { selection } = parse( '<p><b></b>[]</p>' );
  392. const position = selection.getFirstPosition();
  393. const nodeBefore = position.nodeBefore;
  394. expect( Position.createAfter( nodeBefore ).isEqual( position ) ).to.be.true;
  395. } );
  396. it( 'should create positions after `TextProxy`', () => {
  397. const text = new Text( 'abcd' );
  398. const textProxy = new TextProxy( text, 1, 2 );
  399. const position = new Position( text, 3 );
  400. expect( Position.createAfter( textProxy ) ).deep.equal( position );
  401. } );
  402. } );
  403. describe( 'getEditableElement', () => {
  404. it( 'should return null if position is not inside EditableElement', () => {
  405. const position = new Position( new Element( 'p' ), 0 );
  406. expect( position.editableElement ).to.be.null;
  407. } );
  408. it( 'should return EditableElement when position is placed inside', () => {
  409. const document = new Document();
  410. const p = new Element( 'p' );
  411. const editable = new EditableElement( 'div', null, p );
  412. editable._document = document;
  413. const position = new Position( p, 0 );
  414. expect( position.editableElement ).to.equal( editable );
  415. } );
  416. } );
  417. describe( 'getCommonAncestor()', () => {
  418. let div, ul, liUl1, liUl2, texts, section, article, ol, liOl1, liOl2, p;
  419. // |- div
  420. // |- ul
  421. // | |- li
  422. // | | |- foz
  423. // | |- li
  424. // | |- bar
  425. // |- section
  426. // |- Sed id libero at libero tristique
  427. // |- article
  428. // | |- ol
  429. // | | |- li
  430. // | | | |- Lorem ipsum dolor sit amet.
  431. // | | |- li
  432. // | | |- Mauris tincidunt tincidunt leo ac rutrum.
  433. // | |- p
  434. // | | |- Maecenas accumsan tellus.
  435. beforeEach( () => {
  436. texts = {
  437. foz: new Text( 'foz' ),
  438. bar: new Text( 'bar' ),
  439. lorem: new Text( 'Lorem ipsum dolor sit amet.' ),
  440. mauris: new Text( 'Mauris tincidunt tincidunt leo ac rutrum.' ),
  441. maecenas: new Text( 'Maecenas accumsan tellus.' ),
  442. sed: new Text( 'Sed id libero at libero tristique.' )
  443. };
  444. liUl1 = new Element( 'li', null, texts.foz );
  445. liUl2 = new Element( 'li', null, texts.bar );
  446. ul = new Element( 'ul', null, [ liUl1, liUl2 ] );
  447. liOl1 = new Element( 'li', null, texts.lorem );
  448. liOl2 = new Element( 'li', null, texts.mauris );
  449. ol = new Element( 'ol', null, [ liOl1, liOl2 ] );
  450. p = new Element( 'p', null, texts.maecenas );
  451. article = new Element( 'article', null, [ ol, p ] );
  452. section = new Element( 'section', null, [ texts.sed, article ] );
  453. div = new Element( 'div', null, [ ul, section ] );
  454. } );
  455. it( 'for two the same positions returns the parent element', () => {
  456. const afterLoremPosition = new Position( liOl1, 5 );
  457. const otherPosition = Position.createFromPosition( afterLoremPosition );
  458. test( afterLoremPosition, otherPosition, liOl1 );
  459. } );
  460. it( 'for two positions in the same element returns the element', () => {
  461. const startMaecenasPosition = Position.createAt( liOl2, 0 );
  462. const beforeTellusPosition = new Position( liOl2, 18 );
  463. test( startMaecenasPosition, beforeTellusPosition, liOl2 );
  464. } );
  465. it( 'works when one of the positions is nested deeper than the other #1', () => {
  466. const firstPosition = new Position( liUl1, 1 );
  467. const secondPosition = new Position( p, 3 );
  468. test( firstPosition, secondPosition, div );
  469. } );
  470. it( 'works when one of the positions is nested deeper than the other #2', () => {
  471. const firstPosition = new Position( liOl2, 10 );
  472. const secondPosition = new Position( section, 1 );
  473. test( firstPosition, secondPosition, section );
  474. } );
  475. it( 'for two positions in different trees returns null', () => {
  476. const div = new Element( 'div' );
  477. const posInDiv = new Position( div, 0 );
  478. const firstPosition = new Position( liOl2, 10 );
  479. test( posInDiv, firstPosition, null );
  480. } );
  481. function test( positionA, positionB, lca ) {
  482. expect( positionA.getCommonAncestor( positionB ) ).to.equal( lca );
  483. expect( positionB.getCommonAncestor( positionA ) ).to.equal( lca );
  484. }
  485. } );
  486. } );