italic.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Italic from '/ckeditor5/basic-styles/italic.js';
  8. import ItalicEngine from '/ckeditor5/basic-styles/italicengine.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( 'Italic', () => {
  14. let editor;
  15. beforeEach( () => {
  16. editor = new Editor( { 'editor': document.getElementById( 'editor' ) }, {
  17. creator: ClassicCreator,
  18. features: [ Italic ],
  19. toolbar: [ 'italic' ]
  20. } );
  21. return editor.init();
  22. } );
  23. afterEach( () => {
  24. return editor.destroy();
  25. } );
  26. it( 'should be loaded', () => {
  27. expect( editor.plugins.get( Italic ) ).to.be.instanceOf( Italic );
  28. } );
  29. it( 'should load BoldEngine', () => {
  30. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  31. } );
  32. it( 'should register bold feature component', () => {
  33. const controller = editor.ui.featureComponents.create( 'italic' );
  34. expect( controller ).to.be.instanceOf( ButtonController );
  35. } );
  36. it( 'should execute bold command on model execute event', () => {
  37. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  38. const controller = editor.ui.featureComponents.create( 'italic' );
  39. const model = controller.model;
  40. model.fire( 'execute' );
  41. sinon.assert.calledOnce( executeSpy );
  42. sinon.assert.calledWithExactly( executeSpy, 'italic' );
  43. } );
  44. it( 'should bind model to bold command', () => {
  45. const controller = editor.ui.featureComponents.create( 'italic' );
  46. const model = controller.model;
  47. const command = editor.commands.get( 'italic' );
  48. expect( model.isOn ).to.be.false;
  49. expect( command.value ).to.be.false;
  50. expect( model.isEnabled ).to.be.true;
  51. expect( command.isEnabled ).to.be.true;
  52. command.value = true;
  53. expect( model.isOn ).to.equal( true );
  54. command.isEnabled = false;
  55. expect( model.isEnabled ).to.equal( false );
  56. } );
  57. } );