8
0

integration.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  6. import { setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  7. import BalloonToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/balloon/balloontoolbar';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  10. import Table from '../src/table';
  11. import TableToolbar from '../src/tabletoolbar';
  12. import View from '@ckeditor/ckeditor5-ui/src/view';
  13. describe( 'TableToolbar integration', () => {
  14. describe( 'with the BalloonToolbar', () => {
  15. let balloon, balloonToolbar, newEditor, editorElement;
  16. beforeEach( () => {
  17. editorElement = global.document.createElement( 'div' );
  18. global.document.body.appendChild( editorElement );
  19. return ClassicTestEditor
  20. .create( editorElement, {
  21. plugins: [ Table, TableToolbar, BalloonToolbar, Paragraph ]
  22. } )
  23. .then( editor => {
  24. newEditor = editor;
  25. balloon = newEditor.plugins.get( 'ContextualBalloon' );
  26. balloonToolbar = newEditor.plugins.get( 'BalloonToolbar' );
  27. const button = new View();
  28. button.element = global.document.createElement( 'div' );
  29. // There must be at least one toolbar items which is not disabled to show it.
  30. // https://github.com/ckeditor/ckeditor5-ui/issues/269
  31. balloonToolbar.toolbarView.items.add( button );
  32. newEditor.editing.view.isFocused = true;
  33. newEditor.editing.view.getDomRoot().focus();
  34. } );
  35. } );
  36. afterEach( () => {
  37. editorElement.remove();
  38. return newEditor.destroy();
  39. } );
  40. it( 'should prevent the BalloonToolbar from being displayed when an table is selected', () => {
  41. // When table is selected along with text.
  42. setModelData( newEditor.model, '<paragraph>fo[o</paragraph><table><tableRow><tableCell></tableCell></tableRow></table>]' );
  43. balloonToolbar.show();
  44. // BalloonToolbar should be visible.
  45. expect( balloon.visibleView ).to.equal( balloonToolbar.toolbarView );
  46. // When only table is selected.
  47. setModelData( newEditor.model, '<paragraph>foo</paragraph><table><tableRow><tableCell>[]</tableCell></tableRow></table>' );
  48. balloonToolbar.show();
  49. // BalloonToolbar should not be visible.
  50. expect( balloon.visibleView ).to.be.null;
  51. } );
  52. it( 'should listen to BalloonToolbar#show event with the high priority', () => {
  53. const highestPrioritySpy = sinon.spy();
  54. const highPrioritySpy = sinon.spy();
  55. const normalPrioritySpy = sinon.spy();
  56. // Select an table
  57. setModelData( newEditor.model, '<paragraph>foo</paragraph><table><tableRow><tableCell>[]</tableCell></tableRow></table>' );
  58. newEditor.listenTo( balloonToolbar, 'show', highestPrioritySpy, { priority: 'highest' } );
  59. newEditor.listenTo( balloonToolbar, 'show', highPrioritySpy, { priority: 'high' } );
  60. newEditor.listenTo( balloonToolbar, 'show', normalPrioritySpy, { priority: 'normal' } );
  61. balloonToolbar.show();
  62. sinon.assert.calledOnce( highestPrioritySpy );
  63. sinon.assert.notCalled( highPrioritySpy );
  64. sinon.assert.notCalled( normalPrioritySpy );
  65. } );
  66. } );
  67. } );