8
0

strikethroughui.js 2.8 KB

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