superscriptui.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 SuperscriptEditing from '../../src/superscript/superscriptediting';
  8. import SuperscriptUI from '../../src/superscript/superscriptui';
  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( 'SuperscriptUI', () => {
  13. let editor, superView, editorElement;
  14. testUtils.createSinonSandbox();
  15. beforeEach( () => {
  16. editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor
  19. .create( editorElement, {
  20. plugins: [ Paragraph, SuperscriptEditing, SuperscriptUI ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. superView = editor.ui.componentFactory.create( 'superscript' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. editorElement.remove();
  29. return editor.destroy();
  30. } );
  31. it( 'should register superscript feature component', () => {
  32. expect( superView ).to.be.instanceOf( ButtonView );
  33. expect( superView.isOn ).to.be.false;
  34. expect( superView.label ).to.equal( 'Superscript' );
  35. expect( superView.icon ).to.match( /<svg / );
  36. expect( superView.isToggleable ).to.be.true;
  37. } );
  38. it( 'should execute superscript command on model execute event', () => {
  39. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  40. superView.fire( 'execute' );
  41. sinon.assert.calledOnce( executeSpy );
  42. sinon.assert.calledWithExactly( executeSpy, 'superscript' );
  43. } );
  44. it( 'should bind model to superscript command', () => {
  45. const command = editor.commands.get( 'superscript' );
  46. expect( superView.isOn ).to.be.false;
  47. expect( superView.isEnabled ).to.be.true;
  48. command.value = true;
  49. expect( superView.isOn ).to.be.true;
  50. command.isEnabled = false;
  51. expect( superView.isEnabled ).to.be.false;
  52. } );
  53. } );