strikethroughui.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 StrikethroughEditing from '../../src/strikethrough/strikethroughediting';
  8. import StrikethroughUI from '../../src/strikethrough/strikethroughui';
  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( 'StrikethroughUI', () => {
  14. let editor, strikeView, 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, StrikethroughEditing, StrikethroughUI ]
  22. } )
  23. .then( newEditor => {
  24. editor = newEditor;
  25. strikeView = editor.ui.componentFactory.create( 'strikethrough' );
  26. } );
  27. } );
  28. afterEach( () => {
  29. editorElement.remove();
  30. return editor.destroy();
  31. } );
  32. it( 'should register strikethrough feature component', () => {
  33. expect( strikeView ).to.be.instanceOf( ButtonView );
  34. expect( strikeView.isOn ).to.be.false;
  35. expect( strikeView.label ).to.equal( 'Strikethrough' );
  36. expect( strikeView.icon ).to.match( /<svg / );
  37. expect( strikeView.keystroke ).to.equal( 'CTRL+SHIFT+X' );
  38. expect( strikeView.isToggleable ).to.be.true;
  39. } );
  40. it( 'should execute strikethrough command on model execute event', () => {
  41. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  42. strikeView.fire( 'execute' );
  43. sinon.assert.calledOnce( executeSpy );
  44. sinon.assert.calledWithExactly( executeSpy, 'strikethrough' );
  45. } );
  46. it( 'should bind model to strikethrough command', () => {
  47. const command = editor.commands.get( 'strikethrough' );
  48. expect( strikeView.isOn ).to.be.false;
  49. expect( strikeView.isEnabled ).to.be.true;
  50. command.value = true;
  51. expect( strikeView.isOn ).to.be.true;
  52. command.isEnabled = false;
  53. expect( strikeView.isEnabled ).to.be.false;
  54. } );
  55. it( 'should set keystroke in the model', () => {
  56. expect( strikeView.keystroke ).to.equal( 'CTRL+SHIFT+X' );
  57. } );
  58. it( 'should set editor keystroke', () => {
  59. const spy = sinon.spy( editor, 'execute' );
  60. const keyEventData = {
  61. keyCode: keyCodes.x,
  62. shiftKey: true,
  63. ctrlKey: true,
  64. preventDefault: sinon.spy(),
  65. stopPropagation: sinon.spy()
  66. };
  67. const wasHandled = editor.keystrokes.press( keyEventData );
  68. expect( wasHandled ).to.be.true;
  69. expect( spy.calledOnce ).to.be.true;
  70. expect( keyEventData.preventDefault.calledOnce ).to.be.true;
  71. } );
  72. } );