8
0

balloonpanelview.js 22 KB

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