bold.js 2.2 KB

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