8
0

position.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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( 'static _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-required-second-parameter/ );
  121. } );
  122. it( 'should create positions from positions', () => {
  123. const p = new Element( 'p' );
  124. const position = new Position( p, 0 );
  125. const created = Position._createAt( position, 0 );
  126. expect( created.isEqual( position ) ).to.be.true;
  127. expect( created ).to.not.be.equal( position );
  128. } );
  129. it( 'should create positions from node and offset', () => {
  130. const foo = new Text( 'foo' );
  131. const p = new Element( 'p', null, foo );
  132. expect( Position._createAt( foo, 0 ).parent ).to.equal( foo );
  133. expect( Position._createAt( foo, 0 ).offset ).to.equal( 0 );
  134. expect( Position._createAt( foo, 2 ).parent ).to.equal( foo );
  135. expect( Position._createAt( foo, 2 ).offset ).to.equal( 2 );
  136. expect( Position._createAt( p, 1 ).parent ).to.equal( p );
  137. expect( Position._createAt( p, 1 ).offset ).to.equal( 1 );
  138. } );
  139. it( 'should create positions from node and flag', () => {
  140. const foo = new Text( 'foo' );
  141. const p = new Element( 'p', null, foo );
  142. const fooEnd = Position._createAt( foo, 'end' );
  143. const fooBefore = Position._createAt( foo, 'before' );
  144. const fooAfter = Position._createAt( foo, 'after' );
  145. const pEnd = Position._createAt( p, 'end' );
  146. // pBefore and pAfter would throw.
  147. expect( fooEnd.parent ).to.equal( foo );
  148. expect( fooEnd.offset ).to.equal( 3 );
  149. expect( fooBefore.parent ).to.equal( p );
  150. expect( fooBefore.offset ).to.equal( 0 );
  151. expect( fooAfter.parent ).to.equal( p );
  152. expect( fooAfter.offset ).to.equal( 1 );
  153. expect( pEnd.parent ).to.equal( p );
  154. expect( pEnd.offset ).to.equal( 1 );
  155. } );
  156. it( 'should create positions in document fragment', () => {
  157. const foo = new Text( 'foo' );
  158. const docFrag = new DocumentFragment( [ foo ] );
  159. const pStart = Position._createAt( docFrag, 0 );
  160. const pEnd = Position._createAt( docFrag, 'end' );
  161. expect( pStart.parent ).to.equal( docFrag );
  162. expect( pStart.offset ).to.equal( 0 );
  163. expect( pEnd.parent ).to.equal( docFrag );
  164. expect( pEnd.offset ).to.equal( 1 );
  165. } );
  166. } );
  167. describe( 'createFromPosition', () => {
  168. it( 'creates new Position with same parent and offset', () => {
  169. const offset = 50;
  170. const position = new Position( parentMock, offset );
  171. const newPosition = Position._createFromPosition( position );
  172. expect( position ).to.not.equal( newPosition );
  173. expect( position.offset ).to.equal( offset );
  174. expect( position.parent ).to.equal( parentMock );
  175. } );
  176. } );
  177. describe( 'isEqual', () => {
  178. it( 'should return true for same object', () => {
  179. const position = new Position( {}, 12 );
  180. expect( position.isEqual( position ) ).to.be.true;
  181. } );
  182. it( 'should return true for positions with same parent and offset', () => {
  183. const parentMock = {};
  184. const position1 = new Position( parentMock, 12 );
  185. const position2 = new Position( parentMock, 12 );
  186. expect( position1.isEqual( position2 ) ).to.be.true;
  187. } );
  188. it( 'should return false for positions with different parents', () => {
  189. const position1 = new Position( {}, 12 );
  190. const position2 = new Position( {}, 12 );
  191. expect( position1.isEqual( position2 ) ).to.be.false;
  192. } );
  193. it( 'should return false for positions with different positions', () => {
  194. const parentMock = {};
  195. const position1 = new Position( parentMock, 12 );
  196. const position2 = new Position( parentMock, 2 );
  197. expect( position1.isEqual( position2 ) ).to.be.false;
  198. } );
  199. } );
  200. describe( 'isBefore', () => {
  201. it( 'should return false for same positions', () => {
  202. const node = new Node();
  203. const position1 = new Position( node, 10 );
  204. const position2 = new Position( node, 10 );
  205. expect( position1.isBefore( position1 ) ).to.be.false;
  206. expect( position1.isBefore( position2 ) ).to.be.false;
  207. expect( position2.isBefore( position1 ) ).to.be.false;
  208. } );
  209. it( 'should return false if no common ancestor is found', () => {
  210. const t1 = new Text( 'foo' );
  211. const t2 = new Text( 'bar' );
  212. const e1 = new Element( 'p', null, [ t1 ] );
  213. const e2 = new Element( 'p', null, [ t2 ] );
  214. const position1 = new Position( e1, 0 );
  215. const position2 = new Position( e2, 1 );
  216. expect( position1.isBefore( position2 ) );
  217. expect( position2.isBefore( position1 ) );
  218. } );
  219. it( 'should return true if position is before in same node', () => {
  220. const node = new Node();
  221. const p1 = new Position( node, 10 );
  222. const p2 = new Position( node, 5 );
  223. expect( p2.isBefore( p1 ) ).to.be.true;
  224. expect( p1.isBefore( p2 ) ).to.be.false;
  225. } );
  226. it( 'should compare positions that have common parent', () => {
  227. const t1 = new Text( 'foo' );
  228. const t2 = new Text( 'bar' );
  229. const root = new Element( 'p', null, [ t1, t2 ] );
  230. const position1 = new Position( t1, 2 );
  231. const position2 = new Position( t2, 0 );
  232. const position3 = new Position( root, 0 );
  233. const position4 = new Position( root, 2 );
  234. const position5 = new Position( t1, 0 );
  235. const position6 = new Position( root, 1 );
  236. expect( position1.isBefore( position2 ) ).to.be.true;
  237. expect( position2.isBefore( position1 ) ).to.be.false;
  238. expect( position3.isBefore( position1 ) ).to.be.true;
  239. expect( position3.isBefore( position2 ) ).to.be.true;
  240. expect( position1.isBefore( position3 ) ).to.be.false;
  241. expect( position2.isBefore( position3 ) ).to.be.false;
  242. expect( position4.isBefore( position1 ) ).to.be.false;
  243. expect( position4.isBefore( position3 ) ).to.be.false;
  244. expect( position3.isBefore( position4 ) ).to.be.true;
  245. expect( position3.isBefore( position5 ) ).to.be.true;
  246. expect( position6.isBefore( position2 ) ).to.be.true;
  247. expect( position1.isBefore( position6 ) ).to.be.true;
  248. } );
  249. } );
  250. describe( 'isAfter', () => {
  251. it( 'should return false for same positions', () => {
  252. const node = new Node();
  253. const position1 = new Position( node, 10 );
  254. const position2 = new Position( node, 10 );
  255. expect( position1.isAfter( position1 ) ).to.be.false;
  256. expect( position1.isAfter( position2 ) ).to.be.false;
  257. expect( position2.isAfter( position1 ) ).to.be.false;
  258. } );
  259. it( 'should return false if no common ancestor is found', () => {
  260. const t1 = new Text( 'foo' );
  261. const t2 = new Text( 'bar' );
  262. const e1 = new Element( 'p', null, [ t1 ] );
  263. const e2 = new Element( 'p', null, [ t2 ] );
  264. const position1 = new Position( e1, 0 );
  265. const position2 = new Position( e2, 1 );
  266. expect( position1.isAfter( position2 ) );
  267. expect( position2.isAfter( position1 ) );
  268. } );
  269. it( 'should return true if position is after in same node', () => {
  270. const node = new Node();
  271. const p1 = new Position( node, 10 );
  272. const p2 = new Position( node, 5 );
  273. expect( p2.isAfter( p1 ) ).to.be.false;
  274. expect( p1.isAfter( p2 ) ).to.be.true;
  275. } );
  276. it( 'should compare positions that have common parent', () => {
  277. const t1 = new Text( 'foo' );
  278. const t2 = new Text( 'bar' );
  279. const root = new Element( 'p', null, [ t1, t2 ] );
  280. const position1 = new Position( t1, 2 );
  281. const position2 = new Position( t2, 0 );
  282. const position3 = new Position( root, 0 );
  283. const position4 = new Position( root, 2 );
  284. const position5 = new Position( t1, 0 );
  285. const position6 = new Position( root, 1 );
  286. expect( position1.isAfter( position2 ) ).to.be.false;
  287. expect( position2.isAfter( position1 ) ).to.be.true;
  288. expect( position3.isAfter( position1 ) ).to.be.false;
  289. expect( position3.isAfter( position2 ) ).to.be.false;
  290. expect( position1.isAfter( position3 ) ).to.be.true;
  291. expect( position2.isAfter( position3 ) ).to.be.true;
  292. expect( position4.isAfter( position1 ) ).to.be.true;
  293. expect( position4.isAfter( position3 ) ).to.be.true;
  294. expect( position3.isAfter( position4 ) ).to.be.false;
  295. expect( position5.isAfter( position3 ) ).to.be.true;
  296. expect( position2.isAfter( position6 ) ).to.be.true;
  297. } );
  298. } );
  299. describe( 'isAtStart', () => {
  300. it( 'should return true if it is at the start of it\'s parent', () => {
  301. const foo = new Text( 'foo' );
  302. const position = new Position( foo, 0 );
  303. expect( position.isAtStart ).to.be.true;
  304. } );
  305. it( 'should return false if it is not at the start of it\'s parent', () => {
  306. const foo = new Text( 'foo' );
  307. const position = new Position( foo, 1 );
  308. expect( position.isAtStart ).to.be.false;
  309. } );
  310. } );
  311. describe( 'isAtEnd', () => {
  312. it( 'should return true if it is at the end of it\'s parent', () => {
  313. const foo = new Text( 'foo' );
  314. const p = new Element( 'p', null, foo );
  315. expect( new Position( foo, 3 ).isAtEnd ).to.be.true;
  316. expect( new Position( p, 1 ).isAtEnd ).to.be.true;
  317. } );
  318. it( 'should return false if it is not at the end of it\'s parent', () => {
  319. const foo = new Text( 'foo' );
  320. const p = new Element( 'p', null, foo );
  321. expect( new Position( foo, 2 ).isAtEnd ).to.be.false;
  322. expect( new Position( p, 0 ).isAtEnd ).to.be.false;
  323. } );
  324. } );
  325. describe( 'compareWith', () => {
  326. it( 'should return same if positions are same', () => {
  327. const root = new Element();
  328. const position = new Position( root, 0 );
  329. const compared = new Position( root, 0 );
  330. expect( position.compareWith( compared ) ).to.equal( 'same' );
  331. } );
  332. it( 'should return before if the position is before compared one', () => {
  333. const root = new Element();
  334. const position = new Position( root, 0 );
  335. const compared = new Position( root, 1 );
  336. expect( position.compareWith( compared ) ).to.equal( 'before' );
  337. } );
  338. it( 'should return after if the position is after compared one', () => {
  339. const root = new Element();
  340. const position = new Position( root, 4 );
  341. const compared = new Position( root, 1 );
  342. expect( position.compareWith( compared ) ).to.equal( 'after' );
  343. } );
  344. it( 'should return different if positions are in different roots', () => {
  345. const root1 = new Element();
  346. const root2 = new Element();
  347. const position = new Position( root1, 4 );
  348. const compared = new Position( root2, 1 );
  349. expect( position.compareWith( compared ) ).to.equal( 'different' );
  350. } );
  351. it( 'should return correct results if position is in document fragment', () => {
  352. const node = new Element( 'name' );
  353. const docFrag = new DocumentFragment( [ node ] );
  354. const position = new Position( docFrag, 0 );
  355. const compared = new Position( docFrag, 1 );
  356. const posInNode = new Position( node, 0 );
  357. expect( position.compareWith( compared ) ).to.equal( 'before' );
  358. expect( compared.compareWith( position ) ).to.equal( 'after' );
  359. expect( compared.compareWith( compared ) ).to.equal( 'same' );
  360. expect( position.compareWith( posInNode ) ).to.equal( 'before' );
  361. expect( compared.compareWith( posInNode ) ).to.equal( 'after' );
  362. } );
  363. } );
  364. describe( 'static _createBefore()', () => {
  365. it( 'should throw error if one try to create positions before root', () => {
  366. expect( () => {
  367. Position._createBefore( parse( '<p></p>' ) );
  368. } ).to.throw( CKEditorError, /view-position-before-root/ );
  369. } );
  370. it( 'should create positions before `Node`', () => {
  371. const { selection } = parse( '<p>[]<b></b></p>' );
  372. const position = selection.getFirstPosition();
  373. const nodeAfter = position.nodeAfter;
  374. expect( Position._createBefore( nodeAfter ).isEqual( position ) ).to.be.true;
  375. } );
  376. it( 'should create positions before `TextProxy`', () => {
  377. const text = new Text( 'abc' );
  378. const textProxy = new TextProxy( text, 1, 1 );
  379. const position = new Position( text, 1 );
  380. expect( Position._createBefore( textProxy ) ).deep.equal( position );
  381. } );
  382. } );
  383. describe( 'static _createAfter()', () => {
  384. it( 'should throw error if one try to create positions after root', () => {
  385. expect( () => {
  386. Position._createAfter( parse( '<p></p>' ) );
  387. } ).to.throw( CKEditorError, /view-position-after-root/ );
  388. } );
  389. it( 'should create positions after `Node`', () => {
  390. const { selection } = parse( '<p><b></b>[]</p>' );
  391. const position = selection.getFirstPosition();
  392. const nodeBefore = position.nodeBefore;
  393. expect( Position._createAfter( nodeBefore ).isEqual( position ) ).to.be.true;
  394. } );
  395. it( 'should create positions after `TextProxy`', () => {
  396. const text = new Text( 'abcd' );
  397. const textProxy = new TextProxy( text, 1, 2 );
  398. const position = new Position( text, 3 );
  399. expect( Position._createAfter( textProxy ) ).deep.equal( position );
  400. } );
  401. } );
  402. describe( 'getEditableElement', () => {
  403. it( 'should return null if position is not inside EditableElement', () => {
  404. const position = new Position( new Element( 'p' ), 0 );
  405. expect( position.editableElement ).to.be.null;
  406. } );
  407. it( 'should return EditableElement when position is placed inside', () => {
  408. const document = new Document();
  409. const p = new Element( 'p' );
  410. const editable = new EditableElement( 'div', null, p );
  411. editable._document = document;
  412. const position = new Position( p, 0 );
  413. expect( position.editableElement ).to.equal( editable );
  414. } );
  415. } );
  416. describe( 'getCommonAncestor()', () => {
  417. let div, ul, liUl1, liUl2, texts, section, article, ol, liOl1, liOl2, p;
  418. // |- div
  419. // |- ul
  420. // | |- li
  421. // | | |- foz
  422. // | |- li
  423. // | |- bar
  424. // |- section
  425. // |- Sed id libero at libero tristique
  426. // |- article
  427. // | |- ol
  428. // | | |- li
  429. // | | | |- Lorem ipsum dolor sit amet.
  430. // | | |- li
  431. // | | |- Mauris tincidunt tincidunt leo ac rutrum.
  432. // | |- p
  433. // | | |- Maecenas accumsan tellus.
  434. beforeEach( () => {
  435. texts = {
  436. foz: new Text( 'foz' ),
  437. bar: new Text( 'bar' ),
  438. lorem: new Text( 'Lorem ipsum dolor sit amet.' ),
  439. mauris: new Text( 'Mauris tincidunt tincidunt leo ac rutrum.' ),
  440. maecenas: new Text( 'Maecenas accumsan tellus.' ),
  441. sed: new Text( 'Sed id libero at libero tristique.' )
  442. };
  443. liUl1 = new Element( 'li', null, texts.foz );
  444. liUl2 = new Element( 'li', null, texts.bar );
  445. ul = new Element( 'ul', null, [ liUl1, liUl2 ] );
  446. liOl1 = new Element( 'li', null, texts.lorem );
  447. liOl2 = new Element( 'li', null, texts.mauris );
  448. ol = new Element( 'ol', null, [ liOl1, liOl2 ] );
  449. p = new Element( 'p', null, texts.maecenas );
  450. article = new Element( 'article', null, [ ol, p ] );
  451. section = new Element( 'section', null, [ texts.sed, article ] );
  452. div = new Element( 'div', null, [ ul, section ] );
  453. } );
  454. it( 'for two the same positions returns the parent element', () => {
  455. const afterLoremPosition = new Position( liOl1, 5 );
  456. const otherPosition = Position._createFromPosition( afterLoremPosition );
  457. test( afterLoremPosition, otherPosition, liOl1 );
  458. } );
  459. it( 'for two positions in the same element returns the element', () => {
  460. const startMaecenasPosition = Position._createAt( liOl2, 0 );
  461. const beforeTellusPosition = new Position( liOl2, 18 );
  462. test( startMaecenasPosition, beforeTellusPosition, liOl2 );
  463. } );
  464. it( 'works when one of the positions is nested deeper than the other #1', () => {
  465. const firstPosition = new Position( liUl1, 1 );
  466. const secondPosition = new Position( p, 3 );
  467. test( firstPosition, secondPosition, div );
  468. } );
  469. it( 'works when one of the positions is nested deeper than the other #2', () => {
  470. const firstPosition = new Position( liOl2, 10 );
  471. const secondPosition = new Position( section, 1 );
  472. test( firstPosition, secondPosition, section );
  473. } );
  474. it( 'for two positions in different trees returns null', () => {
  475. const div = new Element( 'div' );
  476. const posInDiv = new Position( div, 0 );
  477. const firstPosition = new Position( liOl2, 10 );
  478. test( posInDiv, firstPosition, null );
  479. } );
  480. function test( positionA, positionB, lca ) {
  481. expect( positionA.getCommonAncestor( positionB ) ).to.equal( lca );
  482. expect( positionB.getCommonAncestor( positionA ) ).to.equal( lca );
  483. }
  484. } );
  485. } );