code.js 2.0 KB

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