italic.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Italic from '/ckeditor5/basic-styles/italic.js';
  8. import ItalicEngine from '/ckeditor5/basic-styles/italicengine.js';
  9. import ButtonController from '/ckeditor5/ui/button/button.js';
  10. import testUtils from '/tests/core/_utils/utils.js';
  11. import { keyCodes } from '/ckeditor5/utils/keyboard.js';
  12. testUtils.createSinonSandbox();
  13. describe( 'Italic', () => {
  14. let editor, italicController;
  15. beforeEach( () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor.create( editorElement, {
  19. features: [ Italic ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. italicController = editor.ui.featureComponents.create( 'italic' );
  24. } );
  25. } );
  26. afterEach( () => {
  27. return editor.destroy();
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( Italic ) ).to.be.instanceOf( Italic );
  31. } );
  32. it( 'should load ItalicEngine', () => {
  33. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  34. } );
  35. it( 'should register italic feature component', () => {
  36. expect( italicController ).to.be.instanceOf( ButtonController );
  37. } );
  38. it( 'should execute italic command on model execute event', () => {
  39. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  40. const model = italicController.model;
  41. model.fire( 'execute' );
  42. sinon.assert.calledOnce( executeSpy );
  43. sinon.assert.calledWithExactly( executeSpy, 'italic' );
  44. } );
  45. it( 'should bind model to italic command', () => {
  46. const model = italicController.model;
  47. const command = editor.commands.get( 'italic' );
  48. expect( model.isOn ).to.be.false;
  49. expect( model.isEnabled ).to.be.true;
  50. command.value = true;
  51. expect( model.isOn ).to.be.true;
  52. command.isEnabled = false;
  53. expect( model.isEnabled ).to.be.false;
  54. } );
  55. it( 'should set keystroke in the model', () => {
  56. expect( italicController.model.keystroke ).to.equal( 'CTRL+I' );
  57. } );
  58. it( 'should set editor keystroke', () => {
  59. const spy = sinon.spy( editor, 'execute' );
  60. const wasHandled = editor.keystrokes.press( { keyCode: keyCodes.i, ctrlKey: true } );
  61. expect( wasHandled ).to.be.true;
  62. expect( spy.calledOnce ).to.be.true;
  63. } );
  64. } );