underlineui.js 2.6 KB

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