integration.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @license Copyright (c) 2003-2020, 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 { 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( 'TableContentToolbar 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 allow the BalloonToolbar to be displayed when a table is selected with surrounding text', () => {
  41. setModelData( newEditor.model, '<paragraph>fo[o</paragraph><table><tableRow><tableCell></tableCell></tableRow></table>]' );
  42. balloonToolbar.show();
  43. expect( balloon.visibleView ).to.equal( balloonToolbar.toolbarView );
  44. } );
  45. it( 'should allow the BalloonToolbar to be displayed when a table content is selected', () => {
  46. setModelData(
  47. newEditor.model,
  48. '<paragraph>foo</paragraph><table><tableRow><tableCell><paragraph>x[y]z</paragraph></tableCell></tableRow></table>'
  49. );
  50. balloonToolbar.show();
  51. expect( balloon.visibleView ).to.equal( balloonToolbar.toolbarView );
  52. } );
  53. it( 'should prevent the BalloonToolbar from being displayed when a table is selected as whole', () => {
  54. setModelData(
  55. newEditor.model,
  56. '<paragraph>foo</paragraph>[<table><tableRow><tableCell><paragraph>foo</paragraph></tableCell></tableRow></table>]'
  57. );
  58. balloonToolbar.show();
  59. expect( balloon.visibleView ).to.be.null;
  60. } );
  61. it( 'should listen to BalloonToolbar#show event with the high priority', () => {
  62. const highestPrioritySpy = sinon.spy();
  63. const highPrioritySpy = sinon.spy();
  64. const normalPrioritySpy = sinon.spy();
  65. // Select an table
  66. setModelData(
  67. newEditor.model,
  68. '<paragraph>foo</paragraph>[<table><tableRow><tableCell><paragraph>x</paragraph></tableCell></tableRow></table>]'
  69. );
  70. newEditor.listenTo( balloonToolbar, 'show', highestPrioritySpy, { priority: 'highest' } );
  71. newEditor.listenTo( balloonToolbar, 'show', highPrioritySpy, { priority: 'high' } );
  72. newEditor.listenTo( balloonToolbar, 'show', normalPrioritySpy, { priority: 'normal' } );
  73. balloonToolbar.show();
  74. sinon.assert.calledOnce( highestPrioritySpy );
  75. sinon.assert.notCalled( highPrioritySpy );
  76. sinon.assert.notCalled( normalPrioritySpy );
  77. } );
  78. } );
  79. } );