strikethrough.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @license Copyright (c) 2003-2017, 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 Strikethrough from '../src/strikethrough';
  8. import StrikethroughEngine from '../src/strikethroughengine';
  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. testUtils.createSinonSandbox();
  13. describe( 'Strikethrough', () => {
  14. let editor, strikeView;
  15. beforeEach( () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor
  19. .create( editorElement, {
  20. plugins: [ Strikethrough ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. strikeView = editor.ui.componentFactory.create( 'strikethrough' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. return editor.destroy();
  29. } );
  30. it( 'should be loaded', () => {
  31. expect( editor.plugins.get( Strikethrough ) ).to.be.instanceOf( Strikethrough );
  32. } );
  33. it( 'should load StrikethroughEngine', () => {
  34. expect( editor.plugins.get( StrikethroughEngine ) ).to.be.instanceOf( StrikethroughEngine );
  35. } );
  36. it( 'should register strikethrough feature component', () => {
  37. expect( strikeView ).to.be.instanceOf( ButtonView );
  38. expect( strikeView.isOn ).to.be.false;
  39. expect( strikeView.label ).to.equal( 'Strikethrough' );
  40. expect( strikeView.icon ).to.match( /<svg / );
  41. expect( strikeView.keystroke ).to.equal( 'CTRL+SHIFT+X' );
  42. } );
  43. it( 'should execute strikethrough command on model execute event', () => {
  44. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  45. strikeView.fire( 'execute' );
  46. sinon.assert.calledOnce( executeSpy );
  47. sinon.assert.calledWithExactly( executeSpy, 'strikethrough' );
  48. } );
  49. it( 'should bind model to strikethrough command', () => {
  50. const command = editor.commands.get( 'strikethrough' );
  51. expect( strikeView.isOn ).to.be.false;
  52. expect( strikeView.isEnabled ).to.be.false;
  53. command.value = true;
  54. expect( strikeView.isOn ).to.be.true;
  55. command.isEnabled = true;
  56. expect( strikeView.isEnabled ).to.be.true;
  57. } );
  58. it( 'should set keystroke in the model', () => {
  59. expect( strikeView.keystroke ).to.equal( 'CTRL+SHIFT+X' );
  60. } );
  61. it( 'should set editor keystroke', () => {
  62. const spy = sinon.spy( editor, 'execute' );
  63. const keyEventData = {
  64. keyCode: keyCodes.x,
  65. shiftKey: true,
  66. ctrlKey: true,
  67. preventDefault: sinon.spy(),
  68. stopPropagation: sinon.spy()
  69. };
  70. const wasHandled = editor.keystrokes.press( keyEventData );
  71. expect( wasHandled ).to.be.true;
  72. expect( spy.calledOnce ).to.be.true;
  73. expect( keyEventData.preventDefault.calledOnce ).to.be.true;
  74. } );
  75. } );