underline.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @license Copyright (c) 2003-2018, 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 Underline from '../src/underline';
  8. import UnderlineEngine from '../src/underlineengine';
  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( 'Underline', () => {
  15. let editor, underlineView;
  16. beforeEach( () => {
  17. const editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. return ClassicTestEditor
  20. .create( editorElement, {
  21. plugins: [ Paragraph, Underline ]
  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 be loaded', () => {
  32. expect( editor.plugins.get( Underline ) ).to.be.instanceOf( Underline );
  33. } );
  34. it( 'should load UnderlineEngine', () => {
  35. expect( editor.plugins.get( UnderlineEngine ) ).to.be.instanceOf( UnderlineEngine );
  36. } );
  37. it( 'should register underline feature component', () => {
  38. expect( underlineView ).to.be.instanceOf( ButtonView );
  39. expect( underlineView.isOn ).to.be.false;
  40. expect( underlineView.label ).to.equal( 'Underline' );
  41. expect( underlineView.icon ).to.match( /<svg / );
  42. expect( underlineView.keystroke ).to.equal( 'CTRL+U' );
  43. } );
  44. it( 'should execute underline command on model execute event', () => {
  45. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  46. underlineView.fire( 'execute' );
  47. sinon.assert.calledOnce( executeSpy );
  48. sinon.assert.calledWithExactly( executeSpy, 'underline' );
  49. } );
  50. it( 'should bind model to underline command', () => {
  51. const command = editor.commands.get( 'underline' );
  52. expect( underlineView.isOn ).to.be.false;
  53. expect( underlineView.isEnabled ).to.be.true;
  54. command.value = true;
  55. expect( underlineView.isOn ).to.be.true;
  56. command.isEnabled = false;
  57. expect( underlineView.isEnabled ).to.be.false;
  58. } );
  59. it( 'should set keystroke in the model', () => {
  60. expect( underlineView.keystroke ).to.equal( 'CTRL+U' );
  61. } );
  62. it( 'should set editor keystroke', () => {
  63. const spy = sinon.spy( editor, 'execute' );
  64. const wasHandled = editor.keystrokes.press( {
  65. keyCode: keyCodes.u,
  66. ctrlKey: true,
  67. preventDefault: sinon.spy(),
  68. stopPropagation: sinon.spy()
  69. } );
  70. expect( wasHandled ).to.be.true;
  71. expect( spy.calledOnce ).to.be.true;
  72. } );
  73. } );