italic.js 2.6 KB

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