code.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  12. testUtils.createSinonSandbox();
  13. describe( 'Code', () => {
  14. let editor, codeView;
  15. beforeEach( () => {
  16. const editorElement = document.createElement( 'div' );
  17. document.body.appendChild( editorElement );
  18. return ClassicTestEditor
  19. .create( editorElement, {
  20. plugins: [ Paragraph, Code ]
  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 be loaded', () => {
  31. expect( editor.plugins.get( Code ) ).to.be.instanceOf( Code );
  32. } );
  33. it( 'should load CodeEngine', () => {
  34. expect( editor.plugins.get( CodeEngine ) ).to.be.instanceOf( CodeEngine );
  35. } );
  36. it( 'should register code feature component', () => {
  37. expect( codeView ).to.be.instanceOf( ButtonView );
  38. expect( codeView.isOn ).to.be.false;
  39. expect( codeView.label ).to.equal( 'Code' );
  40. expect( codeView.icon ).to.match( /<svg / );
  41. } );
  42. it( 'should execute code command on model execute event', () => {
  43. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  44. codeView.fire( 'execute' );
  45. sinon.assert.calledOnce( executeSpy );
  46. sinon.assert.calledWithExactly( executeSpy, 'code' );
  47. } );
  48. it( 'should bind model to code command', () => {
  49. const command = editor.commands.get( 'code' );
  50. expect( codeView.isOn ).to.be.false;
  51. expect( codeView.isEnabled ).to.be.true;
  52. command.value = true;
  53. expect( codeView.isOn ).to.be.true;
  54. command.isEnabled = false;
  55. expect( codeView.isEnabled ).to.be.false;
  56. } );
  57. } );