bold.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 ButtonView from 'ckeditor5/ui/button/buttonview.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, boldView;
  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. boldView = 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( boldView ).to.be.instanceOf( ButtonView );
  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. it( 'should set editor keystroke', () => {
  57. const spy = sinon.spy( editor, 'execute' );
  58. const wasHandled = editor.keystrokes.press( { keyCode: keyCodes.b, ctrlKey: true } );
  59. expect( wasHandled ).to.be.true;
  60. expect( spy.calledOnce ).to.be.true;
  61. } );
  62. } );