heading.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from 'tests/core/_utils/classictesteditor.js';
  7. import Heading from 'ckeditor5/heading/heading.js';
  8. import HeadingEngine from 'ckeditor5/heading/headingengine.js';
  9. import DropdownView from 'ckeditor5/ui/dropdown/dropdownview.js';
  10. import testUtils from 'tests/core/_utils/utils.js';
  11. testUtils.createSinonSandbox();
  12. describe( 'Heading', () => {
  13. let editor, dropdown;
  14. beforeEach( () => {
  15. const editorElement = document.createElement( 'div' );
  16. document.body.appendChild( editorElement );
  17. return ClassicTestEditor.create( editorElement, {
  18. features: [ Heading ],
  19. toolbar: [ 'heading' ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. dropdown = editor.ui.featureComponents.create( 'headings' );
  24. } );
  25. } );
  26. afterEach( () => {
  27. return editor.destroy();
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( Heading ) ).to.be.instanceOf( Heading );
  31. } );
  32. it( 'should load FormatsEngine', () => {
  33. expect( editor.plugins.get( HeadingEngine ) ).to.be.instanceOf( HeadingEngine );
  34. } );
  35. it( 'should register formats feature component', () => {
  36. const dropdown = editor.ui.featureComponents.create( 'headings' );
  37. expect( dropdown ).to.be.instanceOf( DropdownView );
  38. } );
  39. it( 'should execute format command on model execute event', () => {
  40. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  41. const dropdown = editor.ui.featureComponents.create( 'headings' );
  42. dropdown.formatId = 'foo';
  43. dropdown.fire( 'execute' );
  44. sinon.assert.calledOnce( executeSpy );
  45. sinon.assert.calledWithExactly( executeSpy, 'heading', { formatId: 'foo' } );
  46. } );
  47. it( 'should focus view after command execution', () => {
  48. const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  49. const dropdown = editor.ui.featureComponents.create( 'headings' );
  50. dropdown.fire( 'execute' );
  51. sinon.assert.calledOnce( focusSpy );
  52. } );
  53. describe( 'model to command binding', () => {
  54. let command;
  55. beforeEach( () => {
  56. command = editor.commands.get( 'heading' );
  57. } );
  58. it( 'isEnabled', () => {
  59. expect( dropdown.buttonView.isEnabled ).to.be.true;
  60. command.isEnabled = false;
  61. expect( dropdown.buttonView.isEnabled ).to.be.false;
  62. } );
  63. it( 'label', () => {
  64. expect( dropdown.buttonView.label ).to.equal( 'Paragraph' );
  65. command.value = command.formats[ 1 ];
  66. expect( dropdown.buttonView.label ).to.equal( 'Heading 1' );
  67. } );
  68. } );
  69. } );