boldui.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import BoldEditing from '../../src/bold/boldediting';
  8. import BoldUI from '../../src/bold/boldui';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  11. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  12. describe( 'BoldUI', () => {
  13. let editor, boldView, editorElement;
  14. testUtils.createSinonSandbox();
  15. beforeEach( () => {
  16. editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor
  19. .create( editorElement, {
  20. plugins: [ Paragraph, BoldEditing, BoldUI ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. boldView = editor.ui.componentFactory.create( 'bold' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. editorElement.remove();
  29. return editor.destroy();
  30. } );
  31. it( 'should register bold feature component', () => {
  32. expect( boldView ).to.be.instanceOf( ButtonView );
  33. expect( boldView.isOn ).to.be.false;
  34. expect( boldView.label ).to.equal( 'Bold' );
  35. expect( boldView.icon ).to.match( /<svg / );
  36. expect( boldView.keystroke ).to.equal( 'CTRL+B' );
  37. expect( boldView.isToggleable ).to.be.true;
  38. } );
  39. it( 'should execute bold command on model execute event', () => {
  40. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  41. boldView.fire( 'execute' );
  42. sinon.assert.calledOnce( executeSpy );
  43. sinon.assert.calledWithExactly( executeSpy, 'bold' );
  44. } );
  45. it( 'should bind model to bold command', () => {
  46. const command = editor.commands.get( 'bold' );
  47. expect( boldView.isOn ).to.be.false;
  48. expect( boldView.isEnabled ).to.be.true;
  49. command.value = true;
  50. expect( boldView.isOn ).to.be.true;
  51. command.isEnabled = false;
  52. expect( boldView.isEnabled ).to.be.false;
  53. } );
  54. it( 'should set keystroke in the model', () => {
  55. expect( boldView.keystroke ).to.equal( 'CTRL+B' );
  56. } );
  57. } );