boldui.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license Copyright (c) 2003-2019, 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;
  14. testUtils.createSinonSandbox();
  15. beforeEach( () => {
  16. const 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. return editor.destroy();
  29. } );
  30. it( 'should register bold feature component', () => {
  31. expect( boldView ).to.be.instanceOf( ButtonView );
  32. expect( boldView.isOn ).to.be.false;
  33. expect( boldView.label ).to.equal( 'Bold' );
  34. expect( boldView.icon ).to.match( /<svg / );
  35. expect( boldView.keystroke ).to.equal( 'CTRL+B' );
  36. expect( boldView.isToggleable ).to.be.true;
  37. } );
  38. it( 'should execute bold command on model execute event', () => {
  39. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  40. boldView.fire( 'execute' );
  41. sinon.assert.calledOnce( executeSpy );
  42. sinon.assert.calledWithExactly( executeSpy, 'bold' );
  43. } );
  44. it( 'should bind model to bold command', () => {
  45. const command = editor.commands.get( 'bold' );
  46. expect( boldView.isOn ).to.be.false;
  47. expect( boldView.isEnabled ).to.be.true;
  48. command.value = true;
  49. expect( boldView.isOn ).to.be.true;
  50. command.isEnabled = false;
  51. expect( boldView.isEnabled ).to.be.false;
  52. } );
  53. it( 'should set keystroke in the model', () => {
  54. expect( boldView.keystroke ).to.equal( 'CTRL+B' );
  55. } );
  56. } );