8
0

balloonpanelview.js 21 KB

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