bold.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import Bold from '../src/bold';
  8. import BoldEngine from '../src/boldengine';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  11. import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
  12. testUtils.createSinonSandbox();
  13. describe( 'Bold', () => {
  14. let editor, boldView;
  15. beforeEach( () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor.create( editorElement, {
  19. plugins: [ Bold ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. boldView = editor.ui.componentFactory.create( 'bold' );
  24. } );
  25. } );
  26. afterEach( () => {
  27. return editor.destroy();
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( Bold ) ).to.be.instanceOf( Bold );
  31. } );
  32. it( 'should load BoldEngine', () => {
  33. expect( editor.plugins.get( BoldEngine ) ).to.be.instanceOf( BoldEngine );
  34. } );
  35. it( 'should register bold feature component', () => {
  36. expect( boldView ).to.be.instanceOf( ButtonView );
  37. expect( boldView.isOn ).to.be.false;
  38. expect( boldView.label ).to.equal( 'Bold' );
  39. expect( boldView.icon ).to.match( /<svg / );
  40. expect( boldView.keystroke ).to.equal( 'CTRL+B' );
  41. } );
  42. it( 'should execute bold command on model execute event', () => {
  43. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  44. boldView.fire( 'execute' );
  45. sinon.assert.calledOnce( executeSpy );
  46. sinon.assert.calledWithExactly( executeSpy, 'bold' );
  47. } );
  48. it( 'should bind model to bold command', () => {
  49. const command = editor.commands.get( 'bold' );
  50. expect( boldView.isOn ).to.be.false;
  51. expect( boldView.isEnabled ).to.be.false;
  52. command.value = true;
  53. expect( boldView.isOn ).to.be.true;
  54. command.isEnabled = true;
  55. expect( boldView.isEnabled ).to.be.true;
  56. } );
  57. it( 'should set keystroke in the model', () => {
  58. expect( boldView.keystroke ).to.equal( 'CTRL+B' );
  59. } );
  60. it( 'should set editor keystroke', () => {
  61. const spy = sinon.spy( editor, 'execute' );
  62. const wasHandled = editor.keystrokes.press( {
  63. keyCode: keyCodes.b,
  64. ctrlKey: true,
  65. preventDefault: sinon.spy(),
  66. stopPropagation: sinon.spy()
  67. } );
  68. expect( wasHandled ).to.be.true;
  69. expect( spy.calledOnce ).to.be.true;
  70. } );
  71. } );