8
0

subscriptui.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 SubscriptEditing from '../../src/subscript/subscriptediting';
  8. import SubscriptUI from '../../src/subscript/subscriptui';
  9. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  10. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  11. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  12. describe( 'SubscriptUI', () => {
  13. let editor, subView;
  14. testUtils.createSinonSandbox();
  15. beforeEach( () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor
  19. .create( editorElement, {
  20. plugins: [ Paragraph, SubscriptEditing, SubscriptUI ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. subView = editor.ui.componentFactory.create( 'subscript' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. return editor.destroy();
  29. } );
  30. it( 'should register subscript feature component', () => {
  31. expect( subView ).to.be.instanceOf( ButtonView );
  32. expect( subView.isOn ).to.be.false;
  33. expect( subView.label ).to.equal( 'Subscript' );
  34. expect( subView.icon ).to.match( /<svg / );
  35. } );
  36. it( 'should execute subscript command on model execute event', () => {
  37. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  38. subView.fire( 'execute' );
  39. sinon.assert.calledOnce( executeSpy );
  40. sinon.assert.calledWithExactly( executeSpy, 'subscript' );
  41. } );
  42. it( 'should bind model to subscript command', () => {
  43. const command = editor.commands.get( 'subscript' );
  44. expect( subView.isOn ).to.be.false;
  45. expect( subView.isEnabled ).to.be.true;
  46. command.value = true;
  47. expect( subView.isOn ).to.be.true;
  48. command.isEnabled = false;
  49. expect( subView.isEnabled ).to.be.false;
  50. } );
  51. } );