underlineui.js 2.7 KB

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