codeblockui.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /* global document */
  6. import CodeBlockEditing from '../src/codeblockediting';
  7. import CodeBlockUI from '../src/codeblockui';
  8. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  9. describe( 'CodeBlockUI', () => {
  10. let editor, command, element;
  11. beforeEach( () => {
  12. element = document.createElement( 'div' );
  13. document.body.appendChild( element );
  14. return ClassicTestEditor
  15. .create( element, {
  16. plugins: [ CodeBlockEditing, CodeBlockUI ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. command = editor.commands.get( 'codeBlock' );
  21. } );
  22. } );
  23. afterEach( () => {
  24. element.remove();
  25. return editor.destroy();
  26. } );
  27. describe( 'codeBlock button', () => {
  28. it( 'has the base properties', () => {
  29. const button = editor.ui.componentFactory.create( 'codeBlock' );
  30. expect( button ).to.have.property( 'label', 'Code block' );
  31. expect( button ).to.have.property( 'icon' );
  32. expect( button ).to.have.property( 'tooltip', true );
  33. expect( button ).to.have.property( 'isToggleable', true );
  34. } );
  35. it( 'has isOn bound to command\'s value', () => {
  36. const button = editor.ui.componentFactory.create( 'codeBlock' );
  37. command.value = false;
  38. expect( button ).to.have.property( 'isOn', false );
  39. command.value = true;
  40. expect( button ).to.have.property( 'isOn', true );
  41. } );
  42. it( 'has isEnabled bound to command\'s isEnabled', () => {
  43. const button = editor.ui.componentFactory.create( 'codeBlock' );
  44. command.isEnabled = true;
  45. expect( button ).to.have.property( 'isEnabled', true );
  46. command.isEnabled = false;
  47. expect( button ).to.have.property( 'isEnabled', false );
  48. } );
  49. it( 'executes command when it\'s executed', () => {
  50. const button = editor.ui.componentFactory.create( 'codeBlock' );
  51. const spy = sinon.stub( editor, 'execute' );
  52. button.fire( 'execute' );
  53. expect( spy.calledOnce ).to.be.true;
  54. expect( spy.args[ 0 ][ 0 ] ).to.equal( 'codeBlock' );
  55. } );
  56. } );
  57. } );