italic.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from 'ckeditor5-core/tests/_utils/classictesteditor';
  7. import Italic from 'ckeditor5-basic-styles/src/italic';
  8. import ItalicEngine from 'ckeditor5-basic-styles/src/italicengine';
  9. import ButtonView from 'ckeditor5-ui/src/button/buttonview';
  10. import testUtils from 'ckeditor5-core/tests/_utils/utils';
  11. import { keyCodes } from 'ckeditor5-utils/src/keyboard';
  12. testUtils.createSinonSandbox();
  13. describe( 'Italic', () => {
  14. let editor, italicView;
  15. beforeEach( () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor.create( editorElement, {
  19. plugins: [ Italic ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. italicView = editor.ui.componentFactory.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( italicView ).to.be.instanceOf( ButtonView );
  37. expect( italicView.isOn ).to.be.false;
  38. expect( italicView.label ).to.equal( 'Italic' );
  39. expect( italicView.icon ).to.match( /<svg / );
  40. expect( italicView.keystroke ).to.equal( 'CTRL+I' );
  41. } );
  42. it( 'should execute italic command on model execute event', () => {
  43. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  44. italicView.fire( 'execute' );
  45. sinon.assert.calledOnce( executeSpy );
  46. sinon.assert.calledWithExactly( executeSpy, 'italic' );
  47. } );
  48. it( 'should bind model to italic command', () => {
  49. const command = editor.commands.get( 'italic' );
  50. expect( italicView.isOn ).to.be.false;
  51. expect( italicView.isEnabled ).to.be.true;
  52. command.value = true;
  53. expect( italicView.isOn ).to.be.true;
  54. command.isEnabled = false;
  55. expect( italicView.isEnabled ).to.be.false;
  56. } );
  57. it( 'should set keystroke in the model', () => {
  58. expect( italicView.keystroke ).to.equal( 'CTRL+I' );
  59. } );
  60. it( 'should set editor keystroke', () => {
  61. const spy = sinon.spy( editor, 'execute' );
  62. const wasHandled = editor.keystrokes.press( { keyCode: keyCodes.i, ctrlKey: true } );
  63. expect( wasHandled ).to.be.true;
  64. expect( spy.calledOnce ).to.be.true;
  65. } );
  66. } );