strikethrough.js 2.9 KB

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