fontsizeui.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import FontSizeEditing from '../../src/fontsize/fontsizeediting';
  7. import FontSizeUI from '../../src/fontsize/fontsizeui';
  8. import fontSizeIcon from '@ckeditor/ckeditor5-core/theme/icons/low-vision.svg';
  9. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  10. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  11. testUtils.createSinonSandbox();
  12. describe( 'FontSizeUI', () => {
  13. let editor, command, element;
  14. beforeEach( () => {
  15. element = document.createElement( 'div' );
  16. document.body.appendChild( element );
  17. return ClassicTestEditor
  18. .create( element, {
  19. plugins: [ FontSizeEditing, FontSizeUI ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. } );
  24. } );
  25. afterEach( () => {
  26. element.remove();
  27. return editor.destroy();
  28. } );
  29. describe( 'fontSize Dropdown', () => {
  30. let dropdown;
  31. beforeEach( () => {
  32. command = editor.commands.get( 'fontSize' );
  33. dropdown = editor.ui.componentFactory.create( 'fontSize' );
  34. } );
  35. it( 'button has the base properties', () => {
  36. const button = dropdown.buttonView;
  37. expect( button ).to.have.property( 'tooltip', 'Font Size' );
  38. expect( button ).to.have.property( 'icon', fontSizeIcon );
  39. expect( button ).to.have.property( 'withText', false );
  40. } );
  41. it( 'should add custom CSS class to dropdown', () => {
  42. const dropdown = editor.ui.componentFactory.create( 'fontSize' );
  43. dropdown.render();
  44. expect( dropdown.element.classList.contains( 'ck-font-size-dropdown' ) ).to.be.true;
  45. } );
  46. it( 'should focus view after command execution', () => {
  47. const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  48. const dropdown = editor.ui.componentFactory.create( 'fontSize' );
  49. dropdown.commandName = 'fontSize';
  50. dropdown.fire( 'execute' );
  51. sinon.assert.calledOnce( focusSpy );
  52. } );
  53. describe( 'model to command binding', () => {
  54. it( 'isEnabled', () => {
  55. command.isEnabled = false;
  56. expect( dropdown.buttonView.isEnabled ).to.be.false;
  57. command.isEnabled = true;
  58. expect( dropdown.buttonView.isEnabled ).to.be.true;
  59. } );
  60. } );
  61. } );
  62. } );