8
0

italicui.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  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, editorElement;
  15. testUtils.createSinonSandbox();
  16. beforeEach( () => {
  17. 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. editorElement.remove();
  30. return editor.destroy();
  31. } );
  32. it( 'should register italic feature component', () => {
  33. expect( italicView ).to.be.instanceOf( ButtonView );
  34. expect( italicView.isOn ).to.be.false;
  35. expect( italicView.label ).to.equal( 'Italic' );
  36. expect( italicView.icon ).to.match( /<svg / );
  37. expect( italicView.keystroke ).to.equal( 'CTRL+I' );
  38. expect( italicView.isToggleable ).to.be.true;
  39. } );
  40. it( 'should execute italic command on model execute event', () => {
  41. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  42. italicView.fire( 'execute' );
  43. sinon.assert.calledOnce( executeSpy );
  44. sinon.assert.calledWithExactly( executeSpy, 'italic' );
  45. } );
  46. it( 'should bind model to italic command', () => {
  47. const command = editor.commands.get( 'italic' );
  48. expect( italicView.isOn ).to.be.false;
  49. expect( italicView.isEnabled ).to.be.true;
  50. command.value = true;
  51. expect( italicView.isOn ).to.be.true;
  52. command.isEnabled = false;
  53. expect( italicView.isEnabled ).to.be.false;
  54. } );
  55. it( 'should set keystroke in the model', () => {
  56. expect( italicView.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( {
  61. keyCode: keyCodes.i,
  62. ctrlKey: true,
  63. preventDefault: sinon.spy(),
  64. stopPropagation: sinon.spy()
  65. } );
  66. expect( wasHandled ).to.be.true;
  67. expect( spy.calledOnce ).to.be.true;
  68. } );
  69. } );