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