bold.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '/tests/core/_utils/classictesteditor.js';
  7. import Bold from '/ckeditor5/basic-styles/bold.js';
  8. import BoldEngine from '/ckeditor5/basic-styles/boldengine.js';
  9. import ButtonController from '/ckeditor5/ui/button/button.js';
  10. import testUtils from '/tests/core/_utils/utils.js';
  11. import { keyCodes } from '/ckeditor5/utils/keyboard.js';
  12. testUtils.createSinonSandbox();
  13. describe( 'Bold', () => {
  14. let editor, boldController;
  15. beforeEach( () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor.create( editorElement, {
  19. features: [ Bold ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. boldController = editor.ui.featureComponents.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( boldController ).to.be.instanceOf( ButtonController );
  37. } );
  38. it( 'should execute bold command on model execute event', () => {
  39. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  40. const model = boldController.model;
  41. model.fire( 'execute' );
  42. sinon.assert.calledOnce( executeSpy );
  43. sinon.assert.calledWithExactly( executeSpy, 'bold' );
  44. } );
  45. it( 'should bind model to bold command', () => {
  46. const model = boldController.model;
  47. const command = editor.commands.get( 'bold' );
  48. expect( model.isOn ).to.be.false;
  49. expect( model.isEnabled ).to.be.true;
  50. command.value = true;
  51. expect( model.isOn ).to.be.true;
  52. command.isEnabled = false;
  53. expect( model.isEnabled ).to.be.false;
  54. } );
  55. it( 'should set CTRL+B keystroke', () => {
  56. const spy = sinon.spy( editor, 'execute' );
  57. const wasHandled = editor.keystrokes.press( { keyCode: keyCodes.b, ctrlKey: true } );
  58. expect( wasHandled ).to.be.true;
  59. expect( spy.calledOnce ).to.be.true;
  60. } );
  61. } );