italicui.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @license Copyright (c) 2003-2018, 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 ItalicEditing from '../../src/italic/italicediting';
  8. import ItalicUI from '../../src/italic/italicui';
  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. describe( 'ItalicUI', () => {
  14. let editor, italicView;
  15. testUtils.createSinonSandbox();
  16. beforeEach( () => {
  17. const editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. return ClassicTestEditor
  20. .create( editorElement, {
  21. plugins: [ Paragraph, ItalicEditing, ItalicUI ]
  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 register italic feature component', () => {
  32. expect( italicView ).to.be.instanceOf( ButtonView );
  33. expect( italicView.isOn ).to.be.false;
  34. expect( italicView.label ).to.equal( 'Italic' );
  35. expect( italicView.icon ).to.match( /<svg / );
  36. expect( italicView.keystroke ).to.equal( 'CTRL+I' );
  37. } );
  38. it( 'should execute italic command on model execute event', () => {
  39. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  40. italicView.fire( 'execute' );
  41. sinon.assert.calledOnce( executeSpy );
  42. sinon.assert.calledWithExactly( executeSpy, 'italic' );
  43. } );
  44. it( 'should bind model to italic command', () => {
  45. const command = editor.commands.get( 'italic' );
  46. expect( italicView.isOn ).to.be.false;
  47. expect( italicView.isEnabled ).to.be.true;
  48. command.value = true;
  49. expect( italicView.isOn ).to.be.true;
  50. command.isEnabled = false;
  51. expect( italicView.isEnabled ).to.be.false;
  52. } );
  53. it( 'should set keystroke in the model', () => {
  54. expect( italicView.keystroke ).to.equal( 'CTRL+I' );
  55. } );
  56. it( 'should set editor keystroke', () => {
  57. const spy = sinon.spy( editor, 'execute' );
  58. const wasHandled = editor.keystrokes.press( {
  59. keyCode: keyCodes.i,
  60. ctrlKey: true,
  61. preventDefault: sinon.spy(),
  62. stopPropagation: sinon.spy()
  63. } );
  64. expect( wasHandled ).to.be.true;
  65. expect( spy.calledOnce ).to.be.true;
  66. } );
  67. } );