integration.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @license Copyright (c) 2003-2017, 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 ContextualToolbar from '@ckeditor/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  10. import Image from '../src/image';
  11. import View from '@ckeditor/ckeditor5-ui/src/view';
  12. describe( 'Image integration', () => {
  13. describe( 'with the ContextualToolbar', () => {
  14. let balloon, contextualToolbar, newEditor, editorElement;
  15. beforeEach( () => {
  16. editorElement = global.document.createElement( 'div' );
  17. global.document.body.appendChild( editorElement );
  18. return ClassicTestEditor.create( editorElement, {
  19. plugins: [ Image, ContextualToolbar, Paragraph ]
  20. } )
  21. .then( editor => {
  22. newEditor = editor;
  23. balloon = newEditor.plugins.get( 'ContextualBalloon' );
  24. contextualToolbar = newEditor.plugins.get( 'ContextualToolbar' );
  25. const button = new View();
  26. button.element = global.document.createElement( 'div' );
  27. // There must be at least one toolbar items which is not disabled to show it.
  28. // https://github.com/ckeditor/ckeditor5-ui/issues/269
  29. contextualToolbar.toolbarView.items.add( button );
  30. newEditor.editing.view.isFocused = true;
  31. } );
  32. } );
  33. afterEach( () => {
  34. editorElement.remove();
  35. return newEditor.destroy();
  36. } );
  37. it( 'should prevent the ContextualToolbar from being displayed when an image is selected', () => {
  38. // When image is selected along with text.
  39. setModelData( newEditor.document, '<paragraph>fo[o</paragraph><image alt="alt text" src="foo.png"></image>]' );
  40. contextualToolbar.show();
  41. // ContextualToolbar should be visible.
  42. expect( balloon.visibleView ).to.equal( contextualToolbar.toolbarView );
  43. // When only image is selected.
  44. setModelData( newEditor.document, '<paragraph>foo</paragraph>[<image alt="alt text" src="foo.png"></image>]' );
  45. contextualToolbar.show();
  46. // ContextualToolbar should not be visible.
  47. expect( balloon.visibleView ).to.be.null;
  48. } );
  49. it( 'should listen to ContextualToolbar#show event with the high priority', () => {
  50. const highestPrioritySpy = sinon.spy();
  51. const highPrioritySpy = sinon.spy();
  52. const normalPrioritySpy = sinon.spy();
  53. // Select an image
  54. setModelData( newEditor.document, '<paragraph>foo</paragraph>[<image alt="alt text" src="foo.png"></image>]' );
  55. newEditor.listenTo( contextualToolbar, 'show', highestPrioritySpy, { priority: 'highest' } );
  56. newEditor.listenTo( contextualToolbar, 'show', highPrioritySpy, { priority: 'high' } );
  57. newEditor.listenTo( contextualToolbar, 'show', normalPrioritySpy, { priority: 'normal' } );
  58. contextualToolbar.show();
  59. sinon.assert.calledOnce( highestPrioritySpy );
  60. sinon.assert.notCalled( highPrioritySpy );
  61. sinon.assert.notCalled( normalPrioritySpy );
  62. } );
  63. } );
  64. } );