rect.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import global from '../../src/dom/global';
  7. import Rect from '../../src/dom/rect';
  8. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  9. testUtils.createSinonSandbox();
  10. describe( 'Rect', () => {
  11. let geometry;
  12. beforeEach( () => {
  13. geometry = {
  14. top: 10,
  15. right: 40,
  16. bottom: 30,
  17. left: 20,
  18. width: 20,
  19. height: 20
  20. };
  21. } );
  22. describe( 'constructor()', () => {
  23. it( 'should store passed object in #_source property', () => {
  24. const obj = {};
  25. const rect = new Rect( obj );
  26. expect( rect._source ).to.equal( obj );
  27. } );
  28. it( 'should accept HTMLElement', () => {
  29. const element = document.createElement( 'div' );
  30. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( geometry );
  31. assertRect( new Rect( element ), geometry );
  32. } );
  33. it( 'should accept Range (non–collapsed)', () => {
  34. const range = document.createRange();
  35. range.selectNode( document.body );
  36. testUtils.sinon.stub( range, 'getClientRects' ).returns( [ geometry ] );
  37. assertRect( new Rect( range ), geometry );
  38. } );
  39. // https://github.com/ckeditor/ckeditor5-utils/issues/153
  40. it( 'should accept Range (collapsed)', () => {
  41. const range = document.createRange();
  42. range.collapse();
  43. testUtils.sinon.stub( range, 'getClientRects' ).returns( [ geometry ] );
  44. assertRect( new Rect( range ), geometry );
  45. } );
  46. // https://github.com/ckeditor/ckeditor5-utils/issues/153
  47. it( 'should accept Range (collapsed, no Range rects available)', () => {
  48. const range = document.createRange();
  49. const element = document.createElement( 'div' );
  50. range.setStart( element, 0 );
  51. range.collapse();
  52. testUtils.sinon.stub( range, 'getClientRects' ).returns( [] );
  53. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( geometry );
  54. const expectedGeometry = Object.assign( {}, geometry );
  55. expectedGeometry.right = expectedGeometry.left;
  56. expectedGeometry.width = 0;
  57. assertRect( new Rect( range ), expectedGeometry );
  58. } );
  59. it( 'should accept the window (viewport)', () => {
  60. testUtils.sinon.stub( global, 'window' ).value( {
  61. innerWidth: 1000,
  62. innerHeight: 500,
  63. scrollX: 100,
  64. scrollY: 200
  65. } );
  66. assertRect( new Rect( global.window ), {
  67. top: 0,
  68. right: 1000,
  69. bottom: 500,
  70. left: 0,
  71. width: 1000,
  72. height: 500
  73. } );
  74. } );
  75. it( 'should accept Rect', () => {
  76. const sourceRect = new Rect( geometry );
  77. const rect = new Rect( sourceRect );
  78. expect( rect ).to.not.equal( sourceRect );
  79. assertRect( rect, geometry );
  80. } );
  81. it( 'should accept ClientRect', () => {
  82. const clientRect = document.body.getBoundingClientRect();
  83. const { top, right, bottom, left, width, height } = clientRect;
  84. const rect = new Rect( clientRect );
  85. assertRect( rect, { top, right, bottom, left, width, height } );
  86. } );
  87. it( 'should accept geometry object', () => {
  88. assertRect( new Rect( geometry ), geometry );
  89. } );
  90. it( 'should copy the properties (Rect)', () => {
  91. const sourceGeometry = Object.assign( {}, geometry );
  92. const sourceRect = new Rect( geometry );
  93. const rect = new Rect( sourceRect );
  94. assertRect( rect, geometry );
  95. rect.top = 100;
  96. rect.width = 200;
  97. assertRect( sourceRect, sourceGeometry );
  98. } );
  99. it( 'should copy the properties (geomerty object)', () => {
  100. const sourceGeometry = Object.assign( {}, geometry );
  101. const rect = new Rect( geometry );
  102. assertRect( rect, geometry );
  103. rect.top = 100;
  104. rect.width = 200;
  105. assertRect( geometry, sourceGeometry );
  106. } );
  107. } );
  108. describe( 'clone()', () => {
  109. it( 'should clone the source rect', () => {
  110. const rect = new Rect( geometry );
  111. const clone = rect.clone();
  112. expect( clone ).to.be.instanceOf( Rect );
  113. expect( clone ).not.equal( rect );
  114. assertRect( clone, rect );
  115. } );
  116. it( 'should preserve #_source', () => {
  117. const rect = new Rect( geometry );
  118. const clone = rect.clone();
  119. expect( clone._source ).to.equal( rect._source );
  120. assertRect( clone, rect );
  121. } );
  122. } );
  123. describe( 'moveTo()', () => {
  124. it( 'should return the source rect', () => {
  125. const rect = new Rect( geometry );
  126. const returned = rect.moveTo( 100, 200 );
  127. expect( returned ).to.equal( rect );
  128. } );
  129. it( 'should move the rect', () => {
  130. const rect = new Rect( geometry );
  131. rect.moveTo( 100, 200 );
  132. assertRect( rect, {
  133. top: 200,
  134. right: 120,
  135. bottom: 220,
  136. left: 100,
  137. width: 20,
  138. height: 20
  139. } );
  140. } );
  141. } );
  142. describe( 'moveBy()', () => {
  143. it( 'should return the source rect', () => {
  144. const rect = new Rect( geometry );
  145. const returned = rect.moveBy( 100, 200 );
  146. expect( returned ).to.equal( rect );
  147. } );
  148. it( 'should move the rect', () => {
  149. const rect = new Rect( geometry );
  150. rect.moveBy( 100, 200 );
  151. assertRect( rect, {
  152. top: 210,
  153. right: 140,
  154. bottom: 230,
  155. left: 120,
  156. width: 20,
  157. height: 20
  158. } );
  159. } );
  160. } );
  161. describe( 'getIntersection()', () => {
  162. it( 'should return a new rect', () => {
  163. const rect = new Rect( geometry );
  164. const insersect = rect.getIntersection( new Rect( geometry ) );
  165. expect( insersect ).to.be.instanceOf( Rect );
  166. expect( insersect ).to.not.equal( rect );
  167. } );
  168. it( 'should calculate the geometry (#1)', () => {
  169. const rectA = new Rect( {
  170. top: 0,
  171. right: 100,
  172. bottom: 100,
  173. left: 0,
  174. width: 100,
  175. height: 100
  176. } );
  177. const rectB = new Rect( {
  178. top: 50,
  179. right: 150,
  180. bottom: 150,
  181. left: 50,
  182. width: 100,
  183. height: 100
  184. } );
  185. const insersect = rectA.getIntersection( rectB );
  186. assertRect( insersect, {
  187. top: 50,
  188. right: 100,
  189. bottom: 100,
  190. left: 50,
  191. width: 50,
  192. height: 50
  193. } );
  194. } );
  195. it( 'should calculate the geometry (#2)', () => {
  196. const rectA = new Rect( {
  197. top: 0,
  198. right: 100,
  199. bottom: 100,
  200. left: 0,
  201. width: 100,
  202. height: 100
  203. } );
  204. const rectB = new Rect( {
  205. top: 0,
  206. right: 200,
  207. bottom: 100,
  208. left: 100,
  209. width: 100,
  210. height: 100
  211. } );
  212. const insersect = rectA.getIntersection( rectB );
  213. assertRect( insersect, {
  214. top: 0,
  215. right: 100,
  216. bottom: 100,
  217. left: 100,
  218. width: 0,
  219. height: 100
  220. } );
  221. } );
  222. it( 'should calculate the geometry (#3)', () => {
  223. const rectA = new Rect( {
  224. top: 0,
  225. right: 100,
  226. bottom: 100,
  227. left: 0,
  228. width: 100,
  229. height: 100
  230. } );
  231. const rectB = new Rect( {
  232. top: 100,
  233. right: 300,
  234. bottom: 200,
  235. left: 200,
  236. width: 100,
  237. height: 100
  238. } );
  239. expect( rectA.getIntersection( rectB ) ).to.be.null;
  240. } );
  241. } );
  242. describe( 'getIntersectionArea()', () => {
  243. it( 'should calculate the area (#1)', () => {
  244. const rectA = new Rect( {
  245. top: 0,
  246. right: 100,
  247. bottom: 100,
  248. left: 0,
  249. width: 100,
  250. height: 100
  251. } );
  252. const rectB = new Rect( {
  253. top: 50,
  254. right: 150,
  255. bottom: 150,
  256. left: 50,
  257. width: 100,
  258. height: 100
  259. } );
  260. expect( rectA.getIntersectionArea( rectB ) ).to.equal( 2500 );
  261. } );
  262. it( 'should calculate the area (#2)', () => {
  263. const rectA = new Rect( {
  264. top: 0,
  265. right: 100,
  266. bottom: 100,
  267. left: 0,
  268. width: 100,
  269. height: 100
  270. } );
  271. const rectB = new Rect( {
  272. top: 0,
  273. right: 200,
  274. bottom: 100,
  275. left: 100,
  276. width: 100,
  277. height: 100
  278. } );
  279. expect( rectA.getIntersectionArea( rectB ) ).to.equal( 0 );
  280. } );
  281. it( 'should calculate the area (#3)', () => {
  282. const rectA = new Rect( {
  283. top: 0,
  284. right: 100,
  285. bottom: 100,
  286. left: 0,
  287. width: 100,
  288. height: 100
  289. } );
  290. const rectB = new Rect( {
  291. top: 100,
  292. right: 300,
  293. bottom: 200,
  294. left: 200,
  295. width: 100,
  296. height: 100
  297. } );
  298. expect( rectA.getIntersectionArea( rectB ) ).to.equal( 0 );
  299. } );
  300. } );
  301. describe( 'getArea()', () => {
  302. it( 'should calculate the area', () => {
  303. const rect = new Rect( {
  304. width: 100,
  305. height: 50
  306. } );
  307. expect( rect.getArea() ).to.equal( 5000 );
  308. } );
  309. } );
  310. describe( 'getVisible()', () => {
  311. let element, range, ancestorA, ancestorB;
  312. beforeEach( () => {
  313. element = document.createElement( 'div' );
  314. range = document.createRange();
  315. ancestorA = document.createElement( 'div' );
  316. ancestorB = document.createElement( 'div' );
  317. ancestorA.append( element );
  318. document.body.appendChild( ancestorA );
  319. } );
  320. afterEach( () => {
  321. ancestorA.remove();
  322. ancestorB.remove();
  323. } );
  324. it( 'should return a new rect', () => {
  325. const rect = new Rect( {} );
  326. const visible = rect.getVisible();
  327. expect( visible ).to.not.equal( rect );
  328. } );
  329. it( 'should not fail when the rect is for document#body', () => {
  330. testUtils.sinon.stub( document.body, 'getBoundingClientRect' ).returns( {
  331. top: 0,
  332. right: 100,
  333. bottom: 100,
  334. left: 0,
  335. width: 100,
  336. height: 100
  337. } );
  338. assertRect( new Rect( document.body ).getVisible(), {
  339. top: 0,
  340. right: 100,
  341. bottom: 100,
  342. left: 0,
  343. width: 100,
  344. height: 100
  345. } );
  346. } );
  347. it( 'should return the visible rect (HTMLElement), partially cropped', () => {
  348. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( {
  349. top: 0,
  350. right: 100,
  351. bottom: 100,
  352. left: 0,
  353. width: 100,
  354. height: 100
  355. } );
  356. testUtils.sinon.stub( ancestorA, 'getBoundingClientRect' ).returns( {
  357. top: 50,
  358. right: 150,
  359. bottom: 150,
  360. left: 50,
  361. width: 100,
  362. height: 100
  363. } );
  364. assertRect( new Rect( element ).getVisible(), {
  365. top: 50,
  366. right: 100,
  367. bottom: 100,
  368. left: 50,
  369. width: 50,
  370. height: 50
  371. } );
  372. } );
  373. it( 'should return the visible rect (HTMLElement), fully visible', () => {
  374. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( {
  375. top: 0,
  376. right: 100,
  377. bottom: 100,
  378. left: 0,
  379. width: 100,
  380. height: 100
  381. } );
  382. testUtils.sinon.stub( ancestorA, 'getBoundingClientRect' ).returns( {
  383. top: 0,
  384. right: 150,
  385. bottom: 150,
  386. left: 0,
  387. width: 150,
  388. height: 150
  389. } );
  390. assertRect( new Rect( element ).getVisible(), {
  391. top: 0,
  392. right: 100,
  393. bottom: 100,
  394. left: 0,
  395. width: 100,
  396. height: 100
  397. } );
  398. } );
  399. it( 'should return the visible rect (HTMLElement), partially cropped, deep ancestor overflow', () => {
  400. ancestorB.append( ancestorA );
  401. document.body.appendChild( ancestorB );
  402. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( {
  403. top: 0,
  404. right: 100,
  405. bottom: 100,
  406. left: 0,
  407. width: 100,
  408. height: 100
  409. } );
  410. testUtils.sinon.stub( ancestorA, 'getBoundingClientRect' ).returns( {
  411. top: 50,
  412. right: 100,
  413. bottom: 100,
  414. left: 0,
  415. width: 50,
  416. height: 50
  417. } );
  418. testUtils.sinon.stub( ancestorB, 'getBoundingClientRect' ).returns( {
  419. top: 0,
  420. right: 150,
  421. bottom: 100,
  422. left: 50,
  423. width: 100,
  424. height: 100
  425. } );
  426. assertRect( new Rect( element ).getVisible(), {
  427. top: 50,
  428. right: 100,
  429. bottom: 100,
  430. left: 50,
  431. width: 50,
  432. height: 50
  433. } );
  434. } );
  435. it( 'should return the visible rect (Range), partially cropped', () => {
  436. range.setStart( ancestorA, 0 );
  437. range.setEnd( ancestorA, 1 );
  438. testUtils.sinon.stub( range, 'getClientRects' ).returns( [ {
  439. top: 0,
  440. right: 100,
  441. bottom: 100,
  442. left: 0,
  443. width: 100,
  444. height: 100
  445. } ] );
  446. testUtils.sinon.stub( ancestorA, 'getBoundingClientRect' ).returns( {
  447. top: 50,
  448. right: 150,
  449. bottom: 150,
  450. left: 50,
  451. width: 100,
  452. height: 100
  453. } );
  454. assertRect( new Rect( range ).getVisible(), {
  455. top: 50,
  456. right: 100,
  457. bottom: 100,
  458. left: 50,
  459. width: 50,
  460. height: 50
  461. } );
  462. } );
  463. it( 'should return null if there\'s no visible rect', () => {
  464. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( {
  465. top: 0,
  466. right: 100,
  467. bottom: 100,
  468. left: 0,
  469. width: 100,
  470. height: 100
  471. } );
  472. testUtils.sinon.stub( ancestorA, 'getBoundingClientRect' ).returns( {
  473. top: 150,
  474. right: 200,
  475. bottom: 200,
  476. left: 150,
  477. width: 50,
  478. height: 50
  479. } );
  480. expect( new Rect( element ).getVisible() ).to.equal( null );
  481. } );
  482. } );
  483. describe( 'isEqual()', () => {
  484. it( 'returns `true` when rects are equal', () => {
  485. const rectA = new Rect( {
  486. top: 10,
  487. right: 20,
  488. bottom: 30,
  489. left: 40,
  490. width: 10,
  491. height: 20
  492. } );
  493. const rectB = new Rect( {
  494. top: 10,
  495. right: 20,
  496. bottom: 30,
  497. left: 40,
  498. width: 10,
  499. height: 20
  500. } );
  501. expect( rectA.isEqual( rectB ) ).to.be.true;
  502. expect( rectB.isEqual( rectA ) ).to.be.true;
  503. expect( rectA.isEqual( rectA ) ).to.be.true;
  504. } );
  505. it( 'returns `false` when rects are different', () => {
  506. const rectA = new Rect( {
  507. top: 10,
  508. right: 20,
  509. bottom: 30,
  510. left: 40,
  511. width: 10,
  512. height: 20
  513. } );
  514. const rectB = new Rect( {
  515. top: 10,
  516. right: 20,
  517. bottom: 30,
  518. left: 40,
  519. width: 10,
  520. height: 30 // !
  521. } );
  522. expect( rectA.isEqual( rectB ) ).to.be.false;
  523. expect( rectB.isEqual( rectA ) ).to.be.false;
  524. } );
  525. } );
  526. describe( 'contains()', () => {
  527. it( 'should return true if rects are the same', () => {
  528. const rectA = new Rect( {
  529. top: 0,
  530. right: 100,
  531. bottom: 100,
  532. left: 0,
  533. width: 100,
  534. height: 100
  535. } );
  536. const rectB = new Rect( {
  537. top: 0,
  538. right: 100,
  539. bottom: 100,
  540. left: 0,
  541. width: 100,
  542. height: 100
  543. } );
  544. expect( rectA.isEqual( rectB ) ).to.be.true;
  545. expect( rectA.contains( rectB ) ).to.be.true;
  546. expect( rectB.contains( rectA ) ).to.be.true;
  547. } );
  548. it( 'should return true if rect is within', () => {
  549. const rectA = new Rect( {
  550. top: 0,
  551. right: 100,
  552. bottom: 100,
  553. left: 0,
  554. width: 100,
  555. height: 100
  556. } );
  557. const rectB = new Rect( {
  558. top: 10,
  559. right: 90,
  560. bottom: 90,
  561. left: 10,
  562. width: 80,
  563. height: 80
  564. } );
  565. expect( rectA.contains( rectB ) ).to.be.true;
  566. expect( rectB.contains( rectA ) ).to.be.false;
  567. } );
  568. it( 'should return false if rect extends beyond the boundaries', () => {
  569. const rectA = new Rect( {
  570. top: 0,
  571. right: 100,
  572. bottom: 100,
  573. left: 0,
  574. width: 100,
  575. height: 100
  576. } );
  577. const rectB = new Rect( {
  578. top: 10,
  579. right: 100,
  580. bottom: 110,
  581. left: 0,
  582. width: 100,
  583. height: 100
  584. } );
  585. expect( rectA.contains( rectB ) ).to.be.false;
  586. expect( rectB.contains( rectA ) ).to.be.false;
  587. } );
  588. it( 'should return false if rect is completely beyond the boundaries', () => {
  589. const rectA = new Rect( {
  590. top: 0,
  591. right: 100,
  592. bottom: 100,
  593. left: 0,
  594. width: 100,
  595. height: 100
  596. } );
  597. const rectB = new Rect( {
  598. top: 110,
  599. right: 100,
  600. bottom: 210,
  601. left: 0,
  602. width: 100,
  603. height: 100
  604. } );
  605. expect( rectA.contains( rectB ) ).to.be.false;
  606. expect( rectB.contains( rectA ) ).to.be.false;
  607. } );
  608. } );
  609. describe( 'excludeScrollbarsAndBorders()', () => {
  610. it( 'should exclude scrollbars and borders of a HTMLElement', () => {
  611. const element = document.createElement( 'div' );
  612. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( geometry );
  613. testUtils.sinon.stub( global.window, 'getComputedStyle' ).returns( {
  614. borderTopWidth: '5px',
  615. borderRightWidth: '10px',
  616. borderLeftWidth: '5px',
  617. borderBottomWidth: '10px'
  618. } );
  619. // Simulate 5px srollbars.
  620. Object.defineProperties( element, {
  621. offsetWidth: {
  622. value: 20
  623. },
  624. offsetHeight: {
  625. value: 20
  626. },
  627. clientWidth: {
  628. value: 10
  629. },
  630. clientHeight: {
  631. value: 10
  632. }
  633. } );
  634. assertRect( new Rect( element ).excludeScrollbarsAndBorders(), {
  635. top: 15,
  636. right: 35,
  637. bottom: 25,
  638. left: 25,
  639. width: 10,
  640. height: 10
  641. } );
  642. } );
  643. it( 'should exclude scrollbars from viewport\'s rect', () => {
  644. testUtils.sinon.stub( global, 'window' ).value( {
  645. innerWidth: 1000,
  646. innerHeight: 500,
  647. scrollX: 100,
  648. scrollY: 200
  649. } );
  650. testUtils.sinon.stub( global, 'document' ).value( {
  651. documentElement: {
  652. clientWidth: 990,
  653. clientHeight: 490
  654. }
  655. } );
  656. assertRect( new Rect( global.window ).excludeScrollbarsAndBorders(), {
  657. top: 0,
  658. right: 990,
  659. bottom: 490,
  660. left: 0,
  661. width: 990,
  662. height: 490
  663. } );
  664. } );
  665. } );
  666. describe( 'getDomRangeRects() ', () => {
  667. it( 'should return rects for a Range (non–collapsed)', () => {
  668. const range = document.createRange();
  669. range.selectNode( document.body );
  670. testUtils.sinon.stub( range, 'getClientRects' ).returns( [ geometry ] );
  671. const rects = Rect.getDomRangeRects( range );
  672. expect( rects ).to.have.length( 1 );
  673. assertRect( rects[ 0 ], geometry );
  674. } );
  675. // https://github.com/ckeditor/ckeditor5-utils/issues/153
  676. it( 'should return rects for a Range (collapsed)', () => {
  677. const range = document.createRange();
  678. const secondGeometry = { top: 20, right: 80, bottom: 60, left: 40, width: 40, height: 40 };
  679. range.collapse();
  680. testUtils.sinon.stub( range, 'getClientRects' ).returns( [ geometry, secondGeometry ] );
  681. const rects = Rect.getDomRangeRects( range );
  682. expect( rects ).to.have.length( 2 );
  683. assertRect( rects[ 0 ], geometry );
  684. assertRect( rects[ 1 ], secondGeometry );
  685. } );
  686. // https://github.com/ckeditor/ckeditor5-utils/issues/153
  687. it( 'should return rects for a Range (collapsed, no Range rects available)', () => {
  688. const range = document.createRange();
  689. const element = document.createElement( 'div' );
  690. range.setStart( element, 0 );
  691. range.collapse();
  692. testUtils.sinon.stub( range, 'getClientRects' ).returns( [] );
  693. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( geometry );
  694. const expectedGeometry = Object.assign( {}, geometry );
  695. expectedGeometry.right = expectedGeometry.left;
  696. expectedGeometry.width = 0;
  697. const rects = Rect.getDomRangeRects( range );
  698. expect( rects ).to.have.length( 1 );
  699. assertRect( rects[ 0 ], expectedGeometry );
  700. } );
  701. } );
  702. } );
  703. function assertRect( rect, expected ) {
  704. expect( rect ).to.deep.equal( expected );
  705. }