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