bold.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. import Editor from '/ckeditor5/editor.js';
  7. import Bold from '/ckeditor5/basic-styles/bold.js';
  8. import BoldEngine from '/ckeditor5/basic-styles/boldengine.js';
  9. import ClassicCreator from '/ckeditor5/creator-classic/classiccreator.js';
  10. import ButtonController from '/ckeditor5/ui/button/button.js';
  11. import testUtils from '/tests/ckeditor5/_utils/utils.js';
  12. testUtils.createSinonSandbox();
  13. describe( 'Bold', () => {
  14. let editor;
  15. beforeEach( () => {
  16. editor = new Editor( { 'editor': document.getElementById( 'editor' ) }, {
  17. creator: ClassicCreator,
  18. features: [ Bold ],
  19. toolbar: [ 'bold' ]
  20. } );
  21. return editor.init();
  22. } );
  23. it( 'should be loaded', () => {
  24. expect( editor.plugins.get( Bold ) ).to.be.instanceOf( Bold );
  25. } );
  26. it( 'should load BoldEngine', () => {
  27. expect( editor.plugins.get( BoldEngine ) ).to.be.instanceOf( BoldEngine );
  28. } );
  29. it( 'should register bold feature component', () => {
  30. const controller = editor.ui.featureComponents.create( 'bold' );
  31. expect( controller ).to.be.instanceOf( ButtonController );
  32. } );
  33. it( 'should execute bold command on model execute event', () => {
  34. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  35. const controller = editor.ui.featureComponents.create( 'bold' );
  36. const model = controller.model;
  37. model.fire( 'execute' );
  38. sinon.assert.calledOnce( executeSpy );
  39. sinon.assert.calledWithExactly( executeSpy, 'bold' );
  40. } );
  41. it( 'should bind model to bold command', () => {
  42. const controller = editor.ui.featureComponents.create( 'bold' );
  43. const model = controller.model;
  44. const command = editor.commands.get( 'bold' );
  45. expect( model.isOn ).to.be.false;
  46. expect( command.value ).to.be.false;
  47. expect( model.isEnabled ).to.be.true;
  48. expect( command.isEnabled ).to.be.true;
  49. command.value = true;
  50. expect( model.isOn ).to.equal( true );
  51. command.isEnabled = false;
  52. expect( model.isEnabled ).to.equal( false );
  53. } );
  54. } );