8
0

contextualballoon.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  6. import ContextualBalloon from '../../../src/panel/balloon/contextualballoon';
  7. import BalloonPanelView from '../../../src/panel/balloon/balloonpanelview';
  8. import View from '../../../src/view';
  9. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  10. import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  11. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  12. import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  13. /* global document, Event */
  14. describe( 'ContextualBalloon', () => {
  15. let editor, editorElement, balloon, viewA, viewB, viewC;
  16. beforeEach( () => {
  17. editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. return ClassicTestEditor
  20. .create( editorElement, {
  21. plugins: [ Paragraph, ContextualBalloon ]
  22. } )
  23. .then( newEditor => {
  24. editor = newEditor;
  25. balloon = editor.plugins.get( ContextualBalloon );
  26. // We don't need to execute BalloonPanel pin and attachTo methods
  27. // it's enough to check if was called with the proper data.
  28. sinon.stub( balloon.view, 'attachTo' ).returns( {} );
  29. sinon.stub( balloon.view, 'pin' ).returns( {} );
  30. viewA = new View();
  31. viewB = new View();
  32. viewC = new View();
  33. // Add viewA to the pane and init viewB.
  34. balloon.add( {
  35. view: viewA,
  36. position: {
  37. target: 'fake'
  38. }
  39. } );
  40. viewB.render();
  41. } );
  42. } );
  43. afterEach( () => {
  44. editor.destroy();
  45. editorElement.remove();
  46. } );
  47. it( 'should create a plugin instance', () => {
  48. expect( balloon ).to.instanceof( Plugin );
  49. expect( balloon ).to.instanceof( ContextualBalloon );
  50. } );
  51. describe( 'pluginName', () => {
  52. it( 'should return plugin by name', () => {
  53. expect( editor.plugins.get( 'ContextualBalloon' ) ).to.equal( balloon );
  54. } );
  55. } );
  56. describe( 'constructor()', () => {
  57. it( 'should create a plugin instance with properties', () => {
  58. expect( balloon.view ).to.instanceof( BalloonPanelView );
  59. } );
  60. describe( 'positionLimiter', () => {
  61. let model, view, viewDocument, root;
  62. beforeEach( () => {
  63. model = editor.model;
  64. view = editor.editing.view;
  65. viewDocument = view.document;
  66. root = viewDocument.getRoot();
  67. } );
  68. it( 'obtains the root of the selection', () => {
  69. setModelData( model, '<paragraph>[]bar</paragraph>' );
  70. expect( balloon.positionLimiter() ).to.equal( view.domConverter.mapViewToDom( root ) );
  71. } );
  72. it( 'does not fail if selection has no #editableElement', () => {
  73. sinon.stub( viewDocument.selection, 'editableElement' ).value( null );
  74. expect( balloon.positionLimiter() ).to.equal( null );
  75. } );
  76. it( 'obtains the farthest root of the selection (nested editable)', () => {
  77. model.schema.register( 'widget', {
  78. allowIn: '$root',
  79. isObject: true
  80. } );
  81. model.schema.register( 'nestedEditable', { allowIn: 'widget' } );
  82. model.schema.extend( '$text', { allowIn: 'nestedEditable' } );
  83. editor.conversion.for( 'downcast' ).elementToElement( {
  84. model: 'widget',
  85. view: ( modelElement, viewWriter ) => viewWriter.createContainerElement( 'figure', { contenteditable: 'false' } )
  86. } );
  87. editor.conversion.for( 'downcast' ).elementToElement( {
  88. model: 'nestedEditable',
  89. view: ( modelElement, viewWriter ) => viewWriter.createContainerElement( 'figcaption', { contenteditable: 'true' } )
  90. } );
  91. setModelData( model, '<widget><nestedEditable>[]foo</nestedEditable></widget>' );
  92. expect( balloon.positionLimiter() ).to.equal( view.domConverter.mapViewToDom( root ) );
  93. } );
  94. } );
  95. it( 'should add balloon panel view to editor `body` collection', () => {
  96. expect( editor.ui.view.body.getIndex( balloon.view ) ).to.above( -1 );
  97. } );
  98. it( 'should register balloon panel element in editor.ui#focusTracker', () => {
  99. editor.ui.focusTracker.isFocused = false;
  100. balloon.add( {
  101. view: viewB,
  102. position: {
  103. target: 'fake',
  104. limiter: balloon.positionLimiter
  105. }
  106. } );
  107. balloon.view.element.dispatchEvent( new Event( 'focus' ) );
  108. expect( editor.ui.focusTracker.isFocused ).to.true;
  109. } );
  110. } );
  111. describe( 'hasView()', () => {
  112. it( 'should return true when given view is in stack', () => {
  113. expect( balloon.hasView( viewA ) ).to.true;
  114. } );
  115. it( 'should return true when given view is in stack but is not visible', () => {
  116. balloon.add( {
  117. view: viewB,
  118. position: {
  119. target: 'fake',
  120. limiter: balloon.positionLimiter
  121. }
  122. } );
  123. expect( balloon.visibleView ).to.equal( viewB );
  124. expect( balloon.hasView( viewA ) ).to.true;
  125. } );
  126. it( 'should return false when given view is not in stack', () => {
  127. expect( balloon.hasView( viewB ) ).to.false;
  128. } );
  129. } );
  130. describe( 'add()', () => {
  131. it( 'should add view to the `main` stack and display in balloon attached using given position options', () => {
  132. const content = balloon.view.content.get( 0 ).content;
  133. expect( content.length ).to.equal( 1 );
  134. expect( content.get( 0 ) ).to.deep.equal( viewA );
  135. expect( balloon.view.pin.calledOnce ).to.true;
  136. sinon.assert.calledWithMatch( balloon.view.pin.firstCall, {
  137. target: 'fake',
  138. limiter: balloon.positionLimiter
  139. } );
  140. } );
  141. it( 'should add view to the custom stack but not display it when other panel is already visible', () => {
  142. balloon.add( {
  143. view: viewB,
  144. panelId: 'second',
  145. position: {
  146. target: 'fake'
  147. }
  148. } );
  149. balloon.add( {
  150. view: viewC,
  151. panelId: 'second',
  152. position: {
  153. target: 'fake'
  154. }
  155. } );
  156. const content = balloon.view.content.get( 0 ).content;
  157. expect( content.length ).to.equal( 1 );
  158. expect( content.get( 0 ) ).to.deep.equal( viewA );
  159. expect( balloon.hasView( viewB ) );
  160. expect( balloon.hasView( viewC ) );
  161. } );
  162. it( 'should add multiple views to he stack and display last one', () => {
  163. balloon.add( {
  164. view: viewB,
  165. position: {
  166. target: 'fake',
  167. limiter: balloon.positionLimiter
  168. }
  169. } );
  170. const content = balloon.view.content.get( 0 ).content;
  171. expect( content.length ).to.equal( 1 );
  172. expect( content.get( 0 ) ).to.deep.equal( viewB );
  173. } );
  174. it( 'should throw an error when try to add the same view more than once', () => {
  175. expect( () => {
  176. balloon.add( {
  177. view: viewA,
  178. position: {
  179. target: 'fake',
  180. limiter: balloon.positionLimiter
  181. }
  182. } );
  183. } ).to.throw( CKEditorError, /^contextualballoon-add-view-exist/ );
  184. } );
  185. it( 'should use a provided limiter instead of #positionLimiter', () => {
  186. balloon.remove( viewA );
  187. balloon.view.pin.resetHistory();
  188. balloon.add( {
  189. view: viewB,
  190. position: {
  191. target: 'foo',
  192. limiter: 'customLimiter'
  193. }
  194. } );
  195. sinon.assert.calledWithMatch( balloon.view.pin, {
  196. target: 'foo',
  197. limiter: 'customLimiter'
  198. } );
  199. } );
  200. it( 'should use a custom #positionLimiter', () => {
  201. balloon.remove( viewA );
  202. balloon.view.pin.resetHistory();
  203. balloon.positionLimiter = 'customLimiter';
  204. balloon.add( {
  205. view: viewB,
  206. position: {
  207. target: 'foo',
  208. }
  209. } );
  210. sinon.assert.calledWithMatch( balloon.view.pin, {
  211. target: 'foo',
  212. limiter: 'customLimiter'
  213. } );
  214. } );
  215. it( 'should not alter the view data if no limiter is provided and the #positionLimiter is used', () => {
  216. const data = {
  217. view: viewB,
  218. position: {
  219. target: 'foo',
  220. }
  221. };
  222. balloon.remove( viewA );
  223. balloon.add( data );
  224. expect( data ).to.deep.equal( {
  225. view: viewB,
  226. position: {
  227. target: 'foo'
  228. }
  229. } );
  230. } );
  231. it( 'should pin balloon to the target element', () => {
  232. sinon.assert.calledOnce( balloon.view.pin );
  233. } );
  234. it( 'should use the position of the last view in the stack', () => {
  235. balloon.add( {
  236. view: viewB,
  237. position: { target: 'other' }
  238. } );
  239. expect( balloon.view.pin.calledTwice ).to.true;
  240. sinon.assert.calledWithMatch( balloon.view.pin.firstCall, {
  241. target: 'fake',
  242. limiter: balloon.positionLimiter
  243. } );
  244. sinon.assert.calledWithMatch( balloon.view.pin.secondCall, {
  245. target: 'other',
  246. limiter: balloon.positionLimiter
  247. } );
  248. } );
  249. it( 'should set additional css class of visible view to BalloonPanelView', () => {
  250. const view = new View();
  251. balloon.add( {
  252. view,
  253. position: {
  254. target: 'fake',
  255. limiter: balloon.positionLimiter
  256. },
  257. balloonClassName: 'foo'
  258. } );
  259. expect( balloon.view.class ).to.equal( 'foo' );
  260. balloon.add( {
  261. view: viewB,
  262. position: {
  263. target: 'fake',
  264. limiter: balloon.positionLimiter
  265. },
  266. balloonClassName: 'bar'
  267. } );
  268. expect( balloon.view.class ).to.equal( 'bar' );
  269. } );
  270. it( 'should hide arrow if `withArrow` option is set to false', () => {
  271. balloon.remove( viewA );
  272. balloon.view.pin.resetHistory();
  273. balloon.add( {
  274. view: viewB,
  275. position: {
  276. target: 'foo'
  277. },
  278. withArrow: false
  279. } );
  280. expect( balloon.view.withArrow ).to.be.false;
  281. } );
  282. it( 'should show arrow if `withArrow` option was not set and previously shown view had hidden arrow', () => {
  283. balloon.remove( viewA );
  284. balloon.view.pin.resetHistory();
  285. balloon.add( {
  286. view: viewB,
  287. position: {
  288. target: 'foo'
  289. },
  290. withArrow: false
  291. } );
  292. expect( balloon.view.withArrow ).to.be.false;
  293. balloon.remove( viewB );
  294. balloon.add( {
  295. view: viewB,
  296. position: {
  297. target: 'foo'
  298. }
  299. } );
  300. expect( balloon.view.withArrow ).to.be.true;
  301. } );
  302. } );
  303. describe( 'visibleView', () => {
  304. it( 'should return data of currently visible view', () => {
  305. expect( balloon.visibleView ).to.equal( viewA );
  306. } );
  307. it( 'should return data of currently visible view when there is more than one in the stack', () => {
  308. balloon.add( {
  309. view: viewB,
  310. position: {
  311. target: 'fake',
  312. limiter: balloon.positionLimiter
  313. }
  314. } );
  315. expect( balloon.visibleView ).to.equal( viewB );
  316. } );
  317. it( 'should return `null` when the stack is empty', () => {
  318. balloon.remove( viewA );
  319. expect( balloon.visibleView ).to.null;
  320. } );
  321. it( 'should be observable', () => {
  322. const spy = sinon.spy();
  323. balloon.on( 'change:visibleView', spy );
  324. balloon.add( { view: viewB } );
  325. sinon.assert.calledOnce( spy );
  326. sinon.assert.calledWith( spy, sinon.match.any, 'visibleView', viewB, viewA );
  327. } );
  328. } );
  329. describe( 'showPanel()', () => {
  330. it( 'should hide current view and display last view from the given panel stack', () => {
  331. balloon.add( {
  332. panelId: 'second',
  333. view: viewB
  334. } );
  335. balloon.add( {
  336. panelId: 'second',
  337. view: viewC
  338. } );
  339. expect( balloon.visibleView ).to.equal( viewA );
  340. balloon.showPanel( 'second' );
  341. expect( balloon.visibleView ).to.equal( viewC );
  342. balloon.showPanel( 'main' );
  343. expect( balloon.visibleView ).to.equal( viewA );
  344. } );
  345. it( 'should do nothing when given panel is already visible', () => {
  346. expect( () => {
  347. balloon.showPanel( 'main' );
  348. } ).to.not.throw();
  349. } );
  350. it( 'should throw an error when there is no panel of given id', () => {
  351. expect( () => {
  352. balloon.showPanel( 'second' );
  353. } ).to.throw( CKEditorError, 'contextualballoon-showpanel-panel-not-exist: Cannot show not existing panel.' );
  354. } );
  355. } );
  356. describe( 'remove()', () => {
  357. it( 'should remove given view and hide balloon when there is no other view to display', () => {
  358. balloon.view.isVisible = true;
  359. balloon.remove( viewA );
  360. expect( balloon.visibleView ).to.null;
  361. expect( balloon.view.isVisible ).to.false;
  362. } );
  363. it( 'should remove given view from not displayed panel', () => {
  364. balloon.add( {
  365. panelId: 'second',
  366. view: viewB
  367. } );
  368. balloon.add( {
  369. panelId: 'second',
  370. view: viewC
  371. } );
  372. balloon.remove( viewB );
  373. expect( balloon.visibleView ).to.equal( viewA );
  374. expect( () => {
  375. balloon.showPanel( 'second' );
  376. } ).to.not.throw();
  377. } );
  378. it( 'should remove not displayed panel if a removed view was the only view in this panel', () => {
  379. balloon.add( {
  380. panelId: 'second',
  381. view: viewB
  382. } );
  383. balloon.remove( viewB );
  384. expect( balloon.visibleView ).to.equal( viewA );
  385. expect( () => {
  386. balloon.showPanel( 'second' );
  387. } ).to.throw();
  388. } );
  389. it( 'should switch panel to the next one when removed view was the last one in the visible panel', () => {
  390. balloon.add( {
  391. panelId: 'second',
  392. view: viewB
  393. } );
  394. balloon.remove( viewA );
  395. expect( balloon.visibleView ).to.equal( viewB );
  396. expect( () => {
  397. balloon.showPanel( 'main' );
  398. } ).to.throw();
  399. } );
  400. it( 'should remove given view and set preceding in the stack as visible when removed view was visible', () => {
  401. balloon.add( {
  402. view: viewB,
  403. position: {
  404. target: 'fake',
  405. limiter: balloon.positionLimiter
  406. }
  407. } );
  408. balloon.remove( viewB );
  409. expect( balloon.visibleView ).to.equal( viewA );
  410. } );
  411. it( 'should remove given view from the stack when view is not visible', () => {
  412. balloon.add( {
  413. view: viewB,
  414. position: {
  415. target: 'fake',
  416. limiter: balloon.positionLimiter
  417. }
  418. } );
  419. balloon.remove( viewA );
  420. expect( balloon.visibleView ).to.equal( viewB );
  421. } );
  422. it( 'should remove given view from a not currently visible stack', () => {
  423. balloon.add( {
  424. view: viewB,
  425. panelId: 'second',
  426. position: {
  427. target: 'fake'
  428. }
  429. } );
  430. balloon.add( {
  431. view: viewC,
  432. panelId: 'second',
  433. position: {
  434. target: 'fake'
  435. }
  436. } );
  437. balloon.remove( viewB );
  438. expect( balloon.hasView( viewB ) ).to.false;
  439. expect( balloon.hasView( viewC ) ).to.true;
  440. // Does not throw, so the panel is there.
  441. expect( () => {
  442. balloon.showPanel( 'second' );
  443. } ).to.not.throw();
  444. } );
  445. it( 'should remove not displayed stack when removied view was the last one in the stack', () => {
  446. balloon.add( {
  447. view: viewB,
  448. panelId: 'second',
  449. position: {
  450. target: 'fake'
  451. }
  452. } );
  453. balloon.remove( viewB );
  454. expect( balloon.hasView( viewB ) ).to.false;
  455. // Does throw, so the panel is not there.
  456. expect( () => {
  457. balloon.showPanel( 'second' );
  458. } ).to.throw();
  459. } );
  460. it( 'should throw an error when there is no given view in the stack', () => {
  461. expect( () => {
  462. balloon.remove( viewB );
  463. } ).to.throw( CKEditorError, /^contextualballoon-remove-view-not-exist/ );
  464. } );
  465. it( 'should set additional css class of visible view to BalloonPanelView', () => {
  466. const view = new View();
  467. balloon.add( {
  468. view,
  469. position: {
  470. target: 'fake',
  471. limiter: balloon.positionLimiter
  472. },
  473. balloonClassName: 'foo'
  474. } );
  475. balloon.add( {
  476. view: viewB,
  477. position: {
  478. target: 'fake',
  479. limiter: balloon.positionLimiter
  480. },
  481. balloonClassName: 'bar'
  482. } );
  483. balloon.remove( viewB );
  484. expect( balloon.view.class ).to.equal( 'foo' );
  485. } );
  486. } );
  487. describe( 'updatePosition()', () => {
  488. it( 'should attach balloon to the target using position option from the last view in the stack', () => {
  489. balloon.add( {
  490. view: viewB,
  491. position: {
  492. target: 'other'
  493. }
  494. } );
  495. balloon.view.pin.resetHistory();
  496. balloon.updatePosition();
  497. expect( balloon.view.pin.calledOnce );
  498. sinon.assert.calledWithMatch( balloon.view.pin.firstCall, {
  499. target: 'other',
  500. limiter: balloon.positionLimiter
  501. } );
  502. } );
  503. it( 'should set given position to the currently visible view and use position from the first view in the stack #1', () => {
  504. balloon.view.pin.resetHistory();
  505. balloon.updatePosition( { target: 'new' } );
  506. expect( balloon.view.pin.calledOnce );
  507. sinon.assert.calledWithMatch( balloon.view.pin.firstCall, {
  508. target: 'new',
  509. limiter: balloon.positionLimiter
  510. } );
  511. } );
  512. it( 'should set given position to the currently visible view and use position from the first view in the stack #2', () => {
  513. balloon.add( {
  514. view: viewB,
  515. position: {
  516. target: 'other'
  517. }
  518. } );
  519. balloon.view.pin.resetHistory();
  520. balloon.updatePosition( { target: 'new' } );
  521. expect( balloon.view.pin.calledOnce );
  522. sinon.assert.calledWithMatch( balloon.view.pin.firstCall, {
  523. target: 'new',
  524. limiter: balloon.positionLimiter
  525. } );
  526. balloon.remove( viewA );
  527. balloon.updatePosition();
  528. expect( balloon.view.pin.calledTwice );
  529. sinon.assert.calledWithMatch( balloon.view.pin.secondCall, {
  530. target: 'new',
  531. limiter: balloon.positionLimiter
  532. } );
  533. } );
  534. it( 'should use a given position limiter instead of the default one', () => {
  535. balloon.view.pin.resetHistory();
  536. balloon.updatePosition( {
  537. target: 'new',
  538. limiter: 'customLimiter'
  539. } );
  540. expect( balloon.view.pin.calledOnce );
  541. sinon.assert.calledWithMatch( balloon.view.pin.firstCall, {
  542. target: 'new',
  543. limiter: 'customLimiter'
  544. } );
  545. } );
  546. it( 'should throw an error when there is no given view in the stack', () => {
  547. expect( () => {
  548. balloon.remove( viewB );
  549. } ).to.throw( CKEditorError, /^contextualballoon-remove-view-not-exist/ );
  550. } );
  551. } );
  552. describe( 'destroy()', () => {
  553. it( 'can be called multiple times', () => {
  554. expect( () => {
  555. balloon.destroy();
  556. balloon.destroy();
  557. } ).to.not.throw();
  558. } );
  559. it( 'should not touch the DOM', () => {
  560. balloon.destroy();
  561. expect( editor.ui.view.body.getIndex( balloon.view ) ).to.not.equal( -1 );
  562. } );
  563. } );
  564. describe( 'rotator view', () => {
  565. let rotatorView;
  566. beforeEach( () => {
  567. rotatorView = balloon.view.content.get( 0 );
  568. } );
  569. it( 'should display navigation when there is more than one panel', () => {
  570. const navigationElement = rotatorView.element.querySelector( '.ck-balloon-rotator__navigation' );
  571. expect( navigationElement.classList.contains( 'ck-hidden' ) ).to.equal( true );
  572. balloon.add( {
  573. view: viewB,
  574. panelId: 'second'
  575. } );
  576. expect( navigationElement.classList.contains( 'ck-hidden' ) ).to.equal( false );
  577. } );
  578. it( 'should display counter', () => {
  579. const counterElement = rotatorView.element.querySelector( '.ck-balloon-rotator__counter' );
  580. expect( counterElement.textContent ).to.equal( '1 of 1' );
  581. balloon.add( {
  582. view: viewB,
  583. panelId: 'second'
  584. } );
  585. expect( counterElement.textContent ).to.equal( '1 of 2' );
  586. balloon.showPanel( 'second' );
  587. expect( counterElement.textContent ).to.equal( '2 of 2' );
  588. } );
  589. it( 'should hide counter when element width is less then 200px', () => {
  590. // To be sure navigation is displayed.
  591. balloon.add( {
  592. view: viewB,
  593. panelId: 'second'
  594. } );
  595. const counterElement = rotatorView.element.querySelector( '.ck-balloon-rotator__counter' );
  596. let mockedWidth = 201;
  597. sinon.stub( rotatorView.element, 'clientWidth' ).get( () => mockedWidth );
  598. balloon.showPanel( 'second' );
  599. expect( counterElement.classList.contains( 'ck-hidden' ) ).to.equal( false );
  600. mockedWidth = 200;
  601. balloon.showPanel( 'main' );
  602. expect( counterElement.classList.contains( 'ck-hidden' ) ).to.equal( true );
  603. mockedWidth = 201;
  604. balloon.updatePosition();
  605. expect( counterElement.classList.contains( 'ck-hidden' ) ).to.equal( false );
  606. } );
  607. it( 'should switch panel to the next one after clicking next button', () => {
  608. balloon.add( {
  609. view: viewB,
  610. panelId: 'second'
  611. } );
  612. balloon.add( {
  613. view: viewC,
  614. panelId: 'third'
  615. } );
  616. expect( balloon.visibleView ).to.equal( viewA );
  617. rotatorView.buttonNextView.fire( 'execute' );
  618. expect( balloon.visibleView ).to.equal( viewB );
  619. rotatorView.buttonNextView.fire( 'execute' );
  620. expect( balloon.visibleView ).to.equal( viewC );
  621. rotatorView.buttonNextView.fire( 'execute' );
  622. expect( balloon.visibleView ).to.equal( viewA );
  623. } );
  624. it( 'should not move focus to the editable when switching not focused view to the next one', () => {
  625. const editableFocusSpy = sinon.spy( editor.editing.view, 'focus' );
  626. balloon.add( {
  627. view: viewB,
  628. panelId: 'second'
  629. } );
  630. rotatorView.buttonNextView.fire( 'execute' );
  631. sinon.assert.notCalled( editableFocusSpy );
  632. } );
  633. it( 'should move focus to the editable when switching focused view to the next one', () => {
  634. const editableFocusSpy = sinon.spy( editor.editing.view, 'focus' );
  635. balloon.add( {
  636. view: viewB,
  637. panelId: 'second'
  638. } );
  639. rotatorView.focusTracker.isFocused = true;
  640. rotatorView.buttonNextView.fire( 'execute' );
  641. sinon.assert.calledOnce( editableFocusSpy );
  642. } );
  643. it( 'should switch panel to the prev one after clicking prev button', () => {
  644. balloon.add( {
  645. view: viewB,
  646. panelId: 'second'
  647. } );
  648. balloon.add( {
  649. view: viewC,
  650. panelId: 'third'
  651. } );
  652. expect( balloon.visibleView ).to.equal( viewA );
  653. rotatorView.buttonPrevView.fire( 'execute' );
  654. expect( balloon.visibleView ).to.equal( viewC );
  655. rotatorView.buttonPrevView.fire( 'execute' );
  656. expect( balloon.visibleView ).to.equal( viewB );
  657. rotatorView.buttonPrevView.fire( 'execute' );
  658. expect( balloon.visibleView ).to.equal( viewA );
  659. } );
  660. it( 'should not move focus to the editable when switching not focused view to the prev one', () => {
  661. const editableFocusSpy = sinon.spy( editor.editing.view, 'focus' );
  662. balloon.add( {
  663. view: viewB,
  664. panelId: 'second'
  665. } );
  666. rotatorView.buttonPrevView.fire( 'execute' );
  667. sinon.assert.notCalled( editableFocusSpy );
  668. } );
  669. it( 'should move focus to the editable when switching focused view to the prev one', () => {
  670. const editableFocusSpy = sinon.spy( editor.editing.view, 'focus' );
  671. balloon.add( {
  672. view: viewB,
  673. panelId: 'second'
  674. } );
  675. rotatorView.focusTracker.isFocused = true;
  676. rotatorView.buttonPrevView.fire( 'execute' );
  677. sinon.assert.calledOnce( editableFocusSpy );
  678. } );
  679. } );
  680. } );