ckfinderui.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. /* global window */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  8. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import CKFinder from '../src/ckfinder';
  11. import browseFilesIcon from '../theme/icons/browse-files.svg';
  12. describe( 'CKFinderUI', () => {
  13. let editorElement, editor, button;
  14. testUtils.createSinonSandbox();
  15. beforeEach( () => {
  16. editorElement = global.document.createElement( 'div' );
  17. global.document.body.appendChild( editorElement );
  18. return ClassicTestEditor
  19. .create( editorElement, {
  20. plugins: [ CKFinder ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. button = editor.ui.componentFactory.create( 'ckfinder' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. editorElement.remove();
  29. return editor.destroy();
  30. } );
  31. it( 'should add the "ckfinder" component to the factory', () => {
  32. expect( button ).to.be.instanceOf( ButtonView );
  33. } );
  34. describe( 'button', () => {
  35. it( 'should bind #isEnabled to the command', () => {
  36. const command = editor.commands.get( 'ckfinder' );
  37. command.isEnabled = true;
  38. expect( button.isEnabled ).to.be.true;
  39. command.isEnabled = false;
  40. expect( button.isEnabled ).to.be.false;
  41. } );
  42. it( 'should set a #label of the #buttonView', () => {
  43. expect( button.label ).to.equal( 'Insert image or file' );
  44. } );
  45. it( 'should set an #icon of the #buttonView', () => {
  46. expect( button.icon ).to.equal( browseFilesIcon );
  47. } );
  48. it( 'should enable tooltips for the #buttonView', () => {
  49. expect( button.tooltip ).to.be.true;
  50. } );
  51. it( 'should execute bold command on model execute event', () => {
  52. window.CKFinder = {
  53. modal: () => {}
  54. };
  55. const executeStub = testUtils.sinon.spy( editor, 'execute' );
  56. button.fire( 'execute' );
  57. sinon.assert.calledOnce( executeStub );
  58. } );
  59. } );
  60. } );