italic.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 Italic from '/ckeditor5/basic-styles/italic.js';
  7. import ItalicEngine from '/ckeditor5/basic-styles/italicengine.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( 'Italic', () => {
  13. let editor, italicController;
  14. beforeEach( () => {
  15. const editorElement = document.createElement( 'div' );
  16. document.body.appendChild( editorElement );
  17. return ClassicTestEditor.create( editorElement, {
  18. features: [ Italic ]
  19. } )
  20. .then( newEditor => {
  21. editor = newEditor;
  22. italicController = editor.ui.featureComponents.create( 'italic' );
  23. } );
  24. } );
  25. afterEach( () => {
  26. return editor.destroy();
  27. } );
  28. it( 'should be loaded', () => {
  29. expect( editor.plugins.get( Italic ) ).to.be.instanceOf( Italic );
  30. } );
  31. it( 'should load ItalicEngine', () => {
  32. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  33. } );
  34. it( 'should register italic feature component', () => {
  35. expect( italicController ).to.be.instanceOf( ButtonController );
  36. } );
  37. it( 'should execute italic command on model execute event', () => {
  38. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  39. const model = italicController.model;
  40. model.fire( 'execute' );
  41. sinon.assert.calledOnce( executeSpy );
  42. sinon.assert.calledWithExactly( executeSpy, 'italic' );
  43. } );
  44. it( 'should bind model to italic command', () => {
  45. const model = italicController.model;
  46. const command = editor.commands.get( 'italic' );
  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+I keystroke', () => {
  55. const spy = sinon.spy( editor, 'execute' );
  56. const wasHandled = editor.keystrokes.press( { keyCode: keyCodes.i, ctrlKey: true } );
  57. expect( wasHandled ).to.be.true;
  58. expect( spy.calledOnce ).to.be.true;
  59. } );
  60. } );