balloonpanelview.js 22 KB

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