8
0

paragraphbuttonui.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 Paragraph from '../src/paragraph';
  8. import Heading from '@ckeditor/ckeditor5-heading/src/heading';
  9. import ParagraphButtonUI from '../src/paragraphbuttonui';
  10. import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  11. import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
  12. import icon from '../theme/icons/paragraph.svg';
  13. describe( 'HeadingButtonUI', () => {
  14. let editorElement, editor;
  15. describe( 'default config', () => {
  16. beforeEach( () => {
  17. editorElement = document.createElement( 'div' );
  18. document.body.appendChild( editorElement );
  19. return ClassicTestEditor
  20. .create( editorElement, {
  21. plugins: [ Paragraph, ParagraphButtonUI, Heading ],
  22. toolbar: [ 'paragraph' ]
  23. } )
  24. .then( newEditor => {
  25. editor = newEditor;
  26. setData( editor.model, '<paragraph>f{}oo</paragraph>' );
  27. } );
  28. } );
  29. afterEach( () => {
  30. editorElement.remove();
  31. return editor.destroy();
  32. } );
  33. it( 'should define default buttons', () => {
  34. const factory = editor.ui.componentFactory;
  35. expect( factory.create( 'paragraph' ) ).to.be.instanceOf( ButtonView );
  36. } );
  37. it( 'should intialize buttons with correct data', () => {
  38. const paragraphButton = editor.ui.componentFactory.create( 'paragraph' );
  39. expect( paragraphButton.label ).to.equal( 'Paragraph' );
  40. expect( paragraphButton.icon ).to.equal( icon );
  41. expect( paragraphButton.tooltip ).to.equal( true );
  42. expect( paragraphButton.isToggleable ).to.equal( true );
  43. } );
  44. it( 'should bind button to command', () => {
  45. const paragraphButton = editor.ui.componentFactory.create( 'paragraph' );
  46. const paragraphCommand = editor.commands.get( 'paragraph' );
  47. expect( paragraphCommand.isEnabled ).to.be.true;
  48. expect( paragraphButton.isEnabled ).to.be.true;
  49. paragraphCommand.isEnabled = false;
  50. expect( paragraphButton.isEnabled ).to.be.false;
  51. expect( paragraphCommand.value ).to.be.true;
  52. expect( paragraphButton.isOn ).to.be.true;
  53. setData( editor.model, '<heading2>f{}oo</heading2>' );
  54. expect( paragraphCommand.value ).to.be.false;
  55. expect( paragraphButton.isOn ).to.be.false;
  56. } );
  57. it( 'should bind button execute to command execute', () => {
  58. const pararaphButton = editor.ui.componentFactory.create( 'paragraph' );
  59. const executeCommandSpy = sinon.spy( editor, 'execute' );
  60. pararaphButton.fire( 'execute' );
  61. sinon.assert.calledOnce( executeCommandSpy );
  62. sinon.assert.calledWithExactly( executeCommandSpy, 'paragraph' );
  63. } );
  64. } );
  65. } );