italic.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import Italic from '../src/italic';
  8. import ItalicEngine from '../src/italicengine';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  11. import { keyCodes } from '@ckeditor/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
  19. .create( editorElement, {
  20. plugins: [ Italic ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. italicView = editor.ui.componentFactory.create( 'italic' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. return editor.destroy();
  29. } );
  30. it( 'should be loaded', () => {
  31. expect( editor.plugins.get( Italic ) ).to.be.instanceOf( Italic );
  32. } );
  33. it( 'should load ItalicEngine', () => {
  34. expect( editor.plugins.get( ItalicEngine ) ).to.be.instanceOf( ItalicEngine );
  35. } );
  36. it( 'should register italic feature component', () => {
  37. expect( italicView ).to.be.instanceOf( ButtonView );
  38. expect( italicView.isOn ).to.be.false;
  39. expect( italicView.label ).to.equal( 'Italic' );
  40. expect( italicView.icon ).to.match( /<svg / );
  41. expect( italicView.keystroke ).to.equal( 'CTRL+I' );
  42. } );
  43. it( 'should execute italic command on model execute event', () => {
  44. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  45. italicView.fire( 'execute' );
  46. sinon.assert.calledOnce( executeSpy );
  47. sinon.assert.calledWithExactly( executeSpy, 'italic' );
  48. } );
  49. it( 'should bind model to italic command', () => {
  50. const command = editor.commands.get( 'italic' );
  51. expect( italicView.isOn ).to.be.false;
  52. expect( italicView.isEnabled ).to.be.false;
  53. command.value = true;
  54. expect( italicView.isOn ).to.be.true;
  55. command.isEnabled = true;
  56. expect( italicView.isEnabled ).to.be.true;
  57. } );
  58. it( 'should set keystroke in the model', () => {
  59. expect( italicView.keystroke ).to.equal( 'CTRL+I' );
  60. } );
  61. it( 'should set editor keystroke', () => {
  62. const spy = sinon.spy( editor, 'execute' );
  63. const wasHandled = editor.keystrokes.press( {
  64. keyCode: keyCodes.i,
  65. ctrlKey: true,
  66. preventDefault: sinon.spy(),
  67. stopPropagation: sinon.spy()
  68. } );
  69. expect( wasHandled ).to.be.true;
  70. expect( spy.calledOnce ).to.be.true;
  71. } );
  72. } );