italicui.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @license Copyright (c) 2003-2019, 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;
  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. expect( italicView.isToggleable ).to.be.true;
  38. } );
  39. it( 'should execute italic command on model execute event', () => {
  40. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  41. italicView.fire( 'execute' );
  42. sinon.assert.calledOnce( executeSpy );
  43. sinon.assert.calledWithExactly( executeSpy, 'italic' );
  44. } );
  45. it( 'should bind model to italic command', () => {
  46. const command = editor.commands.get( 'italic' );
  47. expect( italicView.isOn ).to.be.false;
  48. expect( italicView.isEnabled ).to.be.true;
  49. command.value = true;
  50. expect( italicView.isOn ).to.be.true;
  51. command.isEnabled = false;
  52. expect( italicView.isEnabled ).to.be.false;
  53. } );
  54. it( 'should set keystroke in the model', () => {
  55. expect( italicView.keystroke ).to.equal( 'CTRL+I' );
  56. } );
  57. it( 'should set editor keystroke', () => {
  58. const spy = sinon.spy( editor, 'execute' );
  59. const wasHandled = editor.keystrokes.press( {
  60. keyCode: keyCodes.i,
  61. ctrlKey: true,
  62. preventDefault: sinon.spy(),
  63. stopPropagation: sinon.spy()
  64. } );
  65. expect( wasHandled ).to.be.true;
  66. expect( spy.calledOnce ).to.be.true;
  67. } );
  68. } );