strike.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Rémy Hubscher. 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 Strike from '../src/strike';
  8. import StrikeEngine from '../src/strikeengine';
  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( 'Strike', () => {
  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: [ Strike ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. strikeView = editor.ui.componentFactory.create( 'strike' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. return editor.destroy();
  29. } );
  30. it( 'should be loaded', () => {
  31. expect( editor.plugins.get( Strike ) ).to.be.instanceOf( Strike );
  32. } );
  33. it( 'should load StrikeEngine', () => {
  34. expect( editor.plugins.get( StrikeEngine ) ).to.be.instanceOf( StrikeEngine );
  35. } );
  36. it( 'should register strike feature component', () => {
  37. expect( strikeView ).to.be.instanceOf( ButtonView );
  38. expect( strikeView.isOn ).to.be.false;
  39. expect( strikeView.label ).to.equal( 'Strike' );
  40. expect( strikeView.icon ).to.match( /<svg / );
  41. expect( strikeView.keystroke ).to.equal( 'CTRL+E' );
  42. } );
  43. it( 'should execute strike 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, 'strike' );
  48. } );
  49. it( 'should bind model to strike command', () => {
  50. const command = editor.commands.get( 'strike' );
  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+E' );
  60. } );
  61. it( 'should set editor keystroke', () => {
  62. const spy = sinon.spy( editor, 'execute' );
  63. const keyEventData = {
  64. keyCode: keyCodes.e,
  65. ctrlKey: true,
  66. preventDefault: sinon.spy(),
  67. stopPropagation: sinon.spy()
  68. };
  69. const wasHandled = editor.keystrokes.press( keyEventData );
  70. expect( wasHandled ).to.be.true;
  71. expect( spy.calledOnce ).to.be.true;
  72. expect( keyEventData.preventDefault.calledOnce ).to.be.true;
  73. } );
  74. } );