superscriptui.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 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;
  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, SuperscriptEditing, SuperscriptUI ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. superView = editor.ui.componentFactory.create( 'superscript' );
  25. } );
  26. } );
  27. afterEach( () => {
  28. return editor.destroy();
  29. } );
  30. it( 'should register superscript feature component', () => {
  31. expect( superView ).to.be.instanceOf( ButtonView );
  32. expect( superView.isOn ).to.be.false;
  33. expect( superView.label ).to.equal( 'Superscript' );
  34. expect( superView.icon ).to.match( /<svg / );
  35. expect( superView.isToggleable ).to.be.true;
  36. } );
  37. it( 'should execute superscript command on model execute event', () => {
  38. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  39. superView.fire( 'execute' );
  40. sinon.assert.calledOnce( executeSpy );
  41. sinon.assert.calledWithExactly( executeSpy, 'superscript' );
  42. } );
  43. it( 'should bind model to superscript command', () => {
  44. const command = editor.commands.get( 'superscript' );
  45. expect( superView.isOn ).to.be.false;
  46. expect( superView.isEnabled ).to.be.true;
  47. command.value = true;
  48. expect( superView.isOn ).to.be.true;
  49. command.isEnabled = false;
  50. expect( superView.isEnabled ).to.be.false;
  51. } );
  52. } );