balloonpanelview.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global window, document, Event */
  6. import ViewCollection from '../../../src/viewcollection';
  7. import BalloonPanelView from '../../../src/panel/balloon/balloonpanelview';
  8. import ButtonView from '../../../src/button/buttonview';
  9. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  10. import * as positionUtils from '@ckeditor/ckeditor5-utils/src/dom/position';
  11. testUtils.createSinonSandbox();
  12. describe( 'BalloonPanelView', () => {
  13. let view;
  14. beforeEach( () => {
  15. view = new BalloonPanelView();
  16. view.render();
  17. document.body.appendChild( view.element );
  18. } );
  19. afterEach( () => {
  20. if ( view ) {
  21. view.element.remove();
  22. view.destroy();
  23. }
  24. } );
  25. describe( 'constructor()', () => {
  26. it( 'should create element from template', () => {
  27. expect( view.element.tagName ).to.equal( 'DIV' );
  28. expect( view.element.classList.contains( 'ck-balloon-panel' ) ).to.true;
  29. } );
  30. it( 'should set default values', () => {
  31. expect( view.top ).to.equal( 0 );
  32. expect( view.left ).to.equal( 0 );
  33. expect( view.position ).to.equal( 'arrow_nw' );
  34. expect( view.isVisible ).to.equal( false );
  35. expect( view.withArrow ).to.equal( true );
  36. } );
  37. it( 'creates view#content collection', () => {
  38. expect( view.content ).to.be.instanceOf( ViewCollection );
  39. } );
  40. } );
  41. describe( 'DOM bindings', () => {
  42. describe( 'arrow', () => {
  43. it( 'should react on view#position', () => {
  44. expect( view.element.classList.contains( 'ck-balloon-panel_arrow_nw' ) ).to.true;
  45. view.position = 'arrow_ne';
  46. expect( view.element.classList.contains( 'ck-balloon-panel_arrow_ne' ) ).to.true;
  47. } );
  48. it( 'should react on view#withArrow', () => {
  49. expect( view.element.classList.contains( 'ck-balloon-panel_with-arrow' ) ).to.be.true;
  50. view.withArrow = false;
  51. expect( view.element.classList.contains( 'ck-balloon-panel_with-arrow' ) ).to.be.false;
  52. } );
  53. } );
  54. describe( 'isVisible', () => {
  55. it( 'should react on view#isvisible', () => {
  56. expect( view.element.classList.contains( 'ck-balloon-panel_visible' ) ).to.false;
  57. view.isVisible = true;
  58. expect( view.element.classList.contains( 'ck-balloon-panel_visible' ) ).to.true;
  59. } );
  60. } );
  61. describe( 'styles', () => {
  62. it( 'should react on view#top', () => {
  63. expect( view.element.style.top ).to.equal( '0px' );
  64. view.top = 10;
  65. expect( view.element.style.top ).to.equal( '10px' );
  66. } );
  67. it( 'should react on view#left', () => {
  68. expect( view.element.style.left ).to.equal( '0px' );
  69. view.left = 10;
  70. expect( view.element.style.left ).to.equal( '10px' );
  71. } );
  72. } );
  73. describe( 'className', () => {
  74. it( 'should set additional class to the view#element', () => {
  75. view.className = 'foo';
  76. expect( view.element.classList.contains( 'foo' ) ).to.true;
  77. view.className = '';
  78. expect( view.element.classList.contains( 'foo' ) ).to.false;
  79. } );
  80. } );
  81. describe( 'children', () => {
  82. it( 'should react on view#content', () => {
  83. expect( view.element.childNodes.length ).to.equal( 0 );
  84. const button = new ButtonView( { t() {} } );
  85. view.content.add( button );
  86. expect( view.element.childNodes.length ).to.equal( 1 );
  87. } );
  88. } );
  89. } );
  90. describe( 'show()', () => {
  91. it( 'should set view#isVisible as true', () => {
  92. view.isVisible = false;
  93. view.show();
  94. expect( view.isVisible ).to.true;
  95. } );
  96. } );
  97. describe( 'hide()', () => {
  98. it( 'should set view#isVisible as false', () => {
  99. view.isVisible = true;
  100. view.hide();
  101. expect( view.isVisible ).to.false;
  102. } );
  103. } );
  104. describe( 'attachTo()', () => {
  105. let target, limiter;
  106. beforeEach( () => {
  107. limiter = document.createElement( 'div' );
  108. target = document.createElement( 'div' );
  109. document.body.appendChild( limiter );
  110. document.body.appendChild( target );
  111. // Mock balloon panel element dimensions.
  112. mockBoundingBox( view.element, {
  113. top: 0,
  114. left: 0,
  115. width: 100,
  116. height: 100
  117. } );
  118. // Mock window dimensions.
  119. testUtils.sinon.stub( window, 'innerWidth' ).value( 500 );
  120. testUtils.sinon.stub( window, 'innerHeight' ).value( 500 );
  121. testUtils.sinon.stub( window, 'scrollX' ).value( 0 );
  122. testUtils.sinon.stub( window, 'scrollY' ).value( 0 );
  123. } );
  124. afterEach( () => {
  125. limiter.remove();
  126. target.remove();
  127. } );
  128. it( 'should use default options', () => {
  129. const spy = testUtils.sinon.spy( positionUtils, 'getOptimalPosition' );
  130. view.attachTo( { target } );
  131. sinon.assert.calledWithExactly( spy, sinon.match( {
  132. element: view.element,
  133. target,
  134. positions: [
  135. BalloonPanelView.defaultPositions.southArrowNorthWest,
  136. BalloonPanelView.defaultPositions.southArrowNorthEast,
  137. BalloonPanelView.defaultPositions.northArrowSouthWest,
  138. BalloonPanelView.defaultPositions.northArrowSouthEast
  139. ],
  140. limiter: document.body,
  141. fitInViewport: true
  142. } ) );
  143. } );
  144. describe( 'limited by limiter element', () => {
  145. beforeEach( () => {
  146. // Mock limiter element dimensions.
  147. mockBoundingBox( limiter, {
  148. left: 0,
  149. top: 0,
  150. width: 500,
  151. height: 500
  152. } );
  153. } );
  154. it( 'should put balloon on the `south east` side of the target element at default', () => {
  155. // Place target element at the center of the limiter.
  156. mockBoundingBox( target, {
  157. top: 225,
  158. left: 225,
  159. width: 50,
  160. height: 50
  161. } );
  162. view.attachTo( { target, limiter } );
  163. expect( view.position ).to.equal( 'arrow_nw' );
  164. } );
  165. it( 'should put balloon on the `south east` side of the target element when ' +
  166. 'target is on the top left side of the limiter', () => {
  167. mockBoundingBox( target, {
  168. top: 0,
  169. left: 0,
  170. width: 50,
  171. height: 50
  172. } );
  173. view.attachTo( { target, limiter } );
  174. expect( view.position ).to.equal( 'arrow_nw' );
  175. } );
  176. it( 'should put balloon on the `south west` side of the target element when target is on the right side of the limiter', () => {
  177. mockBoundingBox( target, {
  178. top: 0,
  179. left: 450,
  180. width: 50,
  181. height: 50
  182. } );
  183. view.attachTo( { target, limiter } );
  184. expect( view.position ).to.equal( 'arrow_ne' );
  185. } );
  186. it( 'should put balloon on the `north east` side of the target element when target is on the bottom of the limiter ', () => {
  187. mockBoundingBox( target, {
  188. top: 450,
  189. left: 0,
  190. width: 50,
  191. height: 50
  192. } );
  193. view.attachTo( { target, limiter } );
  194. expect( view.position ).to.equal( 'arrow_sw' );
  195. } );
  196. it( 'should put balloon on the `north west` side of the target element when ' +
  197. 'target is on the bottom right of the limiter', () => {
  198. mockBoundingBox( target, {
  199. top: 450,
  200. left: 450,
  201. width: 50,
  202. height: 50
  203. } );
  204. view.attachTo( { target, limiter } );
  205. expect( view.position ).to.equal( 'arrow_se' );
  206. } );
  207. // https://github.com/ckeditor/ckeditor5-ui-default/issues/126
  208. it( 'works in a positioned ancestor (position: absolute)', () => {
  209. const positionedAncestor = document.createElement( 'div' );
  210. positionedAncestor.style.position = 'absolute';
  211. positionedAncestor.style.top = '100px';
  212. positionedAncestor.style.left = '100px';
  213. positionedAncestor.appendChild( view.element );
  214. document.body.appendChild( positionedAncestor );
  215. positionedAncestor.appendChild( view.element );
  216. mockBoundingBox( positionedAncestor, {
  217. top: 100,
  218. left: 100,
  219. width: 10,
  220. height: 10
  221. } );
  222. mockBoundingBox( target, {
  223. top: 0,
  224. left: 0,
  225. width: 100,
  226. height: 100
  227. } );
  228. view.attachTo( { target, limiter } );
  229. expect( view.top ).to.equal( 15 );
  230. expect( view.left ).to.equal( -80 );
  231. positionedAncestor.remove();
  232. } );
  233. // https://github.com/ckeditor/ckeditor5-ui-default/issues/126
  234. it( 'works in a positioned ancestor (position: static)', () => {
  235. const positionedAncestor = document.createElement( 'div' );
  236. positionedAncestor.style.position = 'static';
  237. positionedAncestor.appendChild( view.element );
  238. document.body.appendChild( positionedAncestor );
  239. positionedAncestor.appendChild( view.element );
  240. mockBoundingBox( target, {
  241. top: 0,
  242. left: 0,
  243. width: 100,
  244. height: 100
  245. } );
  246. view.attachTo( { target, limiter } );
  247. expect( view.top ).to.equal( 115 );
  248. expect( view.left ).to.equal( 20 );
  249. positionedAncestor.remove();
  250. } );
  251. } );
  252. describe( 'limited by viewport', () => {
  253. it( 'should put balloon on the `south west` position when `south east` is limited', () => {
  254. mockBoundingBox( limiter, {
  255. left: 0,
  256. top: 0,
  257. width: 500,
  258. height: 500
  259. } );
  260. mockBoundingBox( target, {
  261. top: 0,
  262. left: 225,
  263. width: 50,
  264. height: 50
  265. } );
  266. // Note: No sandboxing here. Otherwise, it would restore to the previously stubbed value.
  267. sinon.stub( window, 'innerWidth' ).value( 275 );
  268. view.attachTo( { target, limiter } );
  269. expect( view.position ).to.equal( 'arrow_ne' );
  270. } );
  271. it( 'should put balloon on the `south east` position when `south west` is limited', () => {
  272. mockBoundingBox( limiter, {
  273. top: 0,
  274. left: -400,
  275. width: 500,
  276. height: 500
  277. } );
  278. mockBoundingBox( target, {
  279. top: 0,
  280. left: 0,
  281. width: 50,
  282. height: 50
  283. } );
  284. view.attachTo( { target, limiter } );
  285. expect( view.position ).to.equal( 'arrow_nw' );
  286. } );
  287. it( 'should put balloon on the `north east` position when `south east` is limited', () => {
  288. mockBoundingBox( limiter, {
  289. left: 0,
  290. top: 0,
  291. width: 500,
  292. height: 500
  293. } );
  294. mockBoundingBox( target, {
  295. top: 225,
  296. left: 0,
  297. width: 50,
  298. height: 50
  299. } );
  300. // Note: No sandboxing here. Otherwise, it would restore to the previously stubbed value.
  301. sinon.stub( window, 'innerHeight' ).value( 275 );
  302. view.attachTo( { target, limiter } );
  303. expect( view.position ).to.equal( 'arrow_sw' );
  304. } );
  305. it( 'should put balloon on the `south east` position when `north east` is limited', () => {
  306. mockBoundingBox( limiter, {
  307. left: 0,
  308. top: -400,
  309. width: 500,
  310. height: 500
  311. } );
  312. mockBoundingBox( target, {
  313. top: 0,
  314. left: 0,
  315. width: 50,
  316. height: 50
  317. } );
  318. view.attachTo( { target, limiter } );
  319. expect( view.position ).to.equal( 'arrow_nw' );
  320. } );
  321. } );
  322. } );
  323. describe( 'pin() and unpin()', () => {
  324. let attachToSpy, target, targetParent, limiter, notRelatedElement;
  325. beforeEach( () => {
  326. attachToSpy = sinon.spy( view, 'attachTo' );
  327. limiter = document.createElement( 'div' );
  328. targetParent = document.createElement( 'div' );
  329. target = document.createElement( 'div' );
  330. notRelatedElement = document.createElement( 'div' );
  331. view.show();
  332. targetParent.appendChild( target );
  333. document.body.appendChild( targetParent );
  334. document.body.appendChild( limiter );
  335. document.body.appendChild( notRelatedElement );
  336. } );
  337. afterEach( () => {
  338. targetParent.remove();
  339. limiter.remove();
  340. notRelatedElement.remove();
  341. } );
  342. describe( 'pin()', () => {
  343. it( 'should show the balloon', () => {
  344. const spy = sinon.spy( view, 'show' );
  345. view.hide();
  346. view.pin( { target, limiter } );
  347. sinon.assert.calledOnce( spy );
  348. } );
  349. it( 'should start pinning when the balloon is visible', () => {
  350. view.pin( { target, limiter } );
  351. sinon.assert.calledOnce( attachToSpy );
  352. view.hide();
  353. targetParent.dispatchEvent( new Event( 'scroll' ) );
  354. view.show();
  355. sinon.assert.calledTwice( attachToSpy );
  356. targetParent.dispatchEvent( new Event( 'scroll' ) );
  357. sinon.assert.calledThrice( attachToSpy );
  358. } );
  359. it( 'should stop pinning when the balloon becomes invisible', () => {
  360. view.show();
  361. view.pin( { target, limiter } );
  362. sinon.assert.calledOnce( attachToSpy );
  363. view.hide();
  364. targetParent.dispatchEvent( new Event( 'scroll' ) );
  365. sinon.assert.calledOnce( attachToSpy );
  366. } );
  367. it( 'should unpin if already pinned', () => {
  368. const unpinSpy = testUtils.sinon.spy( view, 'unpin' );
  369. view.show();
  370. sinon.assert.notCalled( attachToSpy );
  371. view.pin( { target, limiter } );
  372. sinon.assert.calledOnce( attachToSpy );
  373. view.pin( { target, limiter } );
  374. sinon.assert.calledTwice( unpinSpy );
  375. targetParent.dispatchEvent( new Event( 'scroll' ) );
  376. sinon.assert.calledThrice( attachToSpy );
  377. } );
  378. it( 'should keep the balloon pinned to the target when any of the related elements is scrolled', () => {
  379. view.pin( { target, limiter } );
  380. sinon.assert.calledOnce( attachToSpy );
  381. sinon.assert.calledWith( attachToSpy.lastCall, { target, limiter } );
  382. targetParent.dispatchEvent( new Event( 'scroll' ) );
  383. sinon.assert.calledTwice( attachToSpy );
  384. sinon.assert.calledWith( attachToSpy.lastCall, { target, limiter } );
  385. limiter.dispatchEvent( new Event( 'scroll' ) );
  386. sinon.assert.calledThrice( attachToSpy );
  387. sinon.assert.calledWith( attachToSpy.lastCall, { target, limiter } );
  388. notRelatedElement.dispatchEvent( new Event( 'scroll' ) );
  389. // Nothing's changed.
  390. sinon.assert.calledThrice( attachToSpy );
  391. sinon.assert.calledWith( attachToSpy.lastCall, { target, limiter } );
  392. } );
  393. it( 'should keep the balloon pinned to the target when the browser window is being resized', () => {
  394. view.pin( { target, limiter } );
  395. sinon.assert.calledOnce( attachToSpy );
  396. sinon.assert.calledWith( attachToSpy.lastCall, { target, limiter } );
  397. window.dispatchEvent( new Event( 'resize' ) );
  398. sinon.assert.calledTwice( attachToSpy );
  399. sinon.assert.calledWith( attachToSpy.lastCall, { target, limiter } );
  400. } );
  401. it( 'should stop attaching when the balloon is hidden', () => {
  402. view.pin( { target, limiter } );
  403. sinon.assert.calledOnce( attachToSpy );
  404. view.hide();
  405. window.dispatchEvent( new Event( 'resize' ) );
  406. window.dispatchEvent( new Event( 'scroll' ) );
  407. // Still once.
  408. sinon.assert.calledOnce( attachToSpy );
  409. } );
  410. it( 'should stop attaching once the view is destroyed', () => {
  411. view.pin( { target, limiter } );
  412. sinon.assert.calledOnce( attachToSpy );
  413. view.destroy();
  414. view.element.remove();
  415. view = null;
  416. window.dispatchEvent( new Event( 'resize' ) );
  417. window.dispatchEvent( new Event( 'scroll' ) );
  418. // Still once.
  419. sinon.assert.calledOnce( attachToSpy );
  420. } );
  421. it( 'should set document.body as the default limiter', () => {
  422. view.pin( { target } );
  423. sinon.assert.calledOnce( attachToSpy );
  424. document.body.dispatchEvent( new Event( 'scroll' ) );
  425. sinon.assert.calledTwice( attachToSpy );
  426. } );
  427. it( 'should work for Range as a target', () => {
  428. const element = document.createElement( 'div' );
  429. const range = document.createRange();
  430. element.appendChild( document.createTextNode( 'foo bar' ) );
  431. document.body.appendChild( element );
  432. range.selectNodeContents( element );
  433. view.pin( { target: range } );
  434. sinon.assert.calledOnce( attachToSpy );
  435. element.dispatchEvent( new Event( 'scroll' ) );
  436. sinon.assert.calledTwice( attachToSpy );
  437. element.remove();
  438. } );
  439. it( 'should work for a Rect as a target', () => {
  440. // Just check if this normally works without errors.
  441. const rect = {};
  442. view.pin( { target: rect, limiter } );
  443. sinon.assert.calledOnce( attachToSpy );
  444. limiter.dispatchEvent( new Event( 'scroll' ) );
  445. sinon.assert.calledTwice( attachToSpy );
  446. } );
  447. it( 'should work for a function as a target/limiter', () => {
  448. // Just check if this normally works without errors.
  449. const rect = {};
  450. view.pin( {
  451. target() { return rect; },
  452. limiter() { return limiter; }
  453. } );
  454. sinon.assert.calledOnce( attachToSpy );
  455. limiter.dispatchEvent( new Event( 'scroll' ) );
  456. sinon.assert.calledTwice( attachToSpy );
  457. } );
  458. // https://github.com/ckeditor/ckeditor5-ui/issues/227
  459. it( 'should react to #scroll from anywhere when the target is not an HTMLElement or Range', () => {
  460. const rect = {};
  461. view.pin( { target: rect } );
  462. sinon.assert.calledOnce( attachToSpy );
  463. notRelatedElement.dispatchEvent( new Event( 'scroll' ) );
  464. sinon.assert.calledTwice( attachToSpy );
  465. } );
  466. // https://github.com/ckeditor/ckeditor5-ui/issues/260
  467. it( 'should react to #scroll from anywhere when the limiter is not an HTMLElement` or Range', () => {
  468. const rect = {};
  469. view.pin( { target, limiter: rect } );
  470. sinon.assert.calledOnce( attachToSpy );
  471. notRelatedElement.dispatchEvent( new Event( 'scroll' ) );
  472. sinon.assert.calledTwice( attachToSpy );
  473. } );
  474. } );
  475. describe( 'unpin()', () => {
  476. it( 'should hide the balloon if pinned', () => {
  477. const spy = sinon.spy( view, 'hide' );
  478. view.pin( { target, limiter } );
  479. view.unpin();
  480. sinon.assert.calledOnce( spy );
  481. } );
  482. it( 'should stop attaching', () => {
  483. view.pin( { target, limiter } );
  484. sinon.assert.calledOnce( attachToSpy );
  485. view.unpin();
  486. view.hide();
  487. window.dispatchEvent( new Event( 'resize' ) );
  488. document.dispatchEvent( new Event( 'scroll' ) );
  489. view.show();
  490. window.dispatchEvent( new Event( 'resize' ) );
  491. document.dispatchEvent( new Event( 'scroll' ) );
  492. sinon.assert.calledOnce( attachToSpy );
  493. } );
  494. } );
  495. } );
  496. describe( 'defaultPositions', () => {
  497. let positions, balloonRect, targetRect;
  498. beforeEach( () => {
  499. positions = BalloonPanelView.defaultPositions;
  500. targetRect = {
  501. top: 100,
  502. bottom: 200,
  503. left: 100,
  504. right: 200,
  505. width: 100,
  506. height: 100
  507. };
  508. balloonRect = {
  509. top: 0,
  510. bottom: 0,
  511. left: 0,
  512. right: 0,
  513. width: 50,
  514. height: 50
  515. };
  516. } );
  517. it( 'should have a proper length', () => {
  518. expect( Object.keys( positions ) ).to.have.length( 18 );
  519. } );
  520. // ------- North
  521. it( 'should define the "northArrowSouth" position', () => {
  522. expect( positions.northArrowSouth( targetRect, balloonRect ) ).to.deep.equal( {
  523. top: 35,
  524. left: 125,
  525. name: 'arrow_s'
  526. } );
  527. } );
  528. it( 'should define the "northArrowSouthEast" position', () => {
  529. expect( positions.northArrowSouthEast( targetRect, balloonRect ) ).to.deep.equal( {
  530. top: 35,
  531. left: 130,
  532. name: 'arrow_se'
  533. } );
  534. } );
  535. it( 'should define the "northArrowSouthWest" position', () => {
  536. expect( positions.northArrowSouthWest( targetRect, balloonRect ) ).to.deep.equal( {
  537. top: 35,
  538. left: 120,
  539. name: 'arrow_sw'
  540. } );
  541. } );
  542. // ------- North west
  543. it( 'should define the "northWestArrowSouth" position', () => {
  544. expect( positions.northWestArrowSouth( targetRect, balloonRect ) ).to.deep.equal( {
  545. top: 35,
  546. left: 75,
  547. name: 'arrow_s'
  548. } );
  549. } );
  550. it( 'should define the "northWestArrowSouthWest" position', () => {
  551. expect( positions.northWestArrowSouthWest( targetRect, balloonRect ) ).to.deep.equal( {
  552. top: 35,
  553. left: 70,
  554. name: 'arrow_sw'
  555. } );
  556. } );
  557. it( 'should define the "northWestArrowSouthEast" position', () => {
  558. expect( positions.northWestArrowSouthEast( targetRect, balloonRect ) ).to.deep.equal( {
  559. top: 35,
  560. left: 80,
  561. name: 'arrow_se'
  562. } );
  563. } );
  564. // ------- North east
  565. it( 'should define the "northEastArrowSouth" position', () => {
  566. expect( positions.northEastArrowSouth( targetRect, balloonRect ) ).to.deep.equal( {
  567. top: 35,
  568. left: 175,
  569. name: 'arrow_s'
  570. } );
  571. } );
  572. it( 'should define the "northEastArrowSouthEast" position', () => {
  573. expect( positions.northEastArrowSouthEast( targetRect, balloonRect ) ).to.deep.equal( {
  574. top: 35,
  575. left: 180,
  576. name: 'arrow_se'
  577. } );
  578. } );
  579. it( 'should define the "northEastArrowSouthWest" position', () => {
  580. expect( positions.northEastArrowSouthWest( targetRect, balloonRect ) ).to.deep.equal( {
  581. top: 35,
  582. left: 170,
  583. name: 'arrow_sw'
  584. } );
  585. } );
  586. // ------- South
  587. it( 'should define the "southArrowNorth" position', () => {
  588. expect( positions.southArrowNorth( targetRect, balloonRect ) ).to.deep.equal( {
  589. top: 215,
  590. left: 125,
  591. name: 'arrow_n'
  592. } );
  593. } );
  594. it( 'should define the "southArrowNorthEast" position', () => {
  595. expect( positions.southArrowNorthEast( targetRect, balloonRect ) ).to.deep.equal( {
  596. top: 215,
  597. left: 130,
  598. name: 'arrow_ne'
  599. } );
  600. } );
  601. it( 'should define the "southArrowNorthWest" position', () => {
  602. expect( positions.southArrowNorthWest( targetRect, balloonRect ) ).to.deep.equal( {
  603. top: 215,
  604. left: 120,
  605. name: 'arrow_nw'
  606. } );
  607. } );
  608. // ------- South west
  609. it( 'should define the "southWestArrowNorth" position', () => {
  610. expect( positions.southWestArrowNorth( targetRect, balloonRect ) ).to.deep.equal( {
  611. top: 215,
  612. left: 75,
  613. name: 'arrow_n'
  614. } );
  615. } );
  616. it( 'should define the "southWestArrowNorthWest" position', () => {
  617. expect( positions.southWestArrowNorthWest( targetRect, balloonRect ) ).to.deep.equal( {
  618. top: 215,
  619. left: 70,
  620. name: 'arrow_nw'
  621. } );
  622. } );
  623. it( 'should define the "southWestArrowNorthEast" position', () => {
  624. expect( positions.southWestArrowNorthEast( targetRect, balloonRect ) ).to.deep.equal( {
  625. top: 215,
  626. left: 80,
  627. name: 'arrow_ne'
  628. } );
  629. } );
  630. // ------- South east
  631. it( 'should define the "southEastArrowNorth" position', () => {
  632. expect( positions.southEastArrowNorth( targetRect, balloonRect ) ).to.deep.equal( {
  633. top: 215,
  634. left: 175,
  635. name: 'arrow_n'
  636. } );
  637. } );
  638. it( 'should define the "southEastArrowNorthEast" position', () => {
  639. expect( positions.southEastArrowNorthEast( targetRect, balloonRect ) ).to.deep.equal( {
  640. top: 215,
  641. left: 180,
  642. name: 'arrow_ne'
  643. } );
  644. } );
  645. it( 'should define the "southEastArrowNorthWest" position', () => {
  646. expect( positions.southEastArrowNorthWest( targetRect, balloonRect ) ).to.deep.equal( {
  647. top: 215,
  648. left: 170,
  649. name: 'arrow_nw'
  650. } );
  651. } );
  652. } );
  653. } );
  654. function mockBoundingBox( element, data ) {
  655. const boundingBox = Object.assign( {}, data );
  656. boundingBox.right = boundingBox.left + boundingBox.width;
  657. boundingBox.bottom = boundingBox.top + boundingBox.height;
  658. testUtils.sinon.stub( element, 'getBoundingClientRect' ).returns( boundingBox );
  659. }