heading.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 ListDropdown from '/ckeditor5/ui/dropdown/list/listdropdown.js';
  10. import testUtils from '/tests/core/_utils/utils.js';
  11. testUtils.createSinonSandbox();
  12. describe( 'Heading', () => {
  13. let editor, controller;
  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. controller = 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 controller = editor.ui.featureComponents.create( 'headings' );
  37. expect( controller ).to.be.instanceOf( ListDropdown );
  38. } );
  39. it( 'should execute format command on model execute event', () => {
  40. const executeSpy = testUtils.sinon.spy( editor, 'execute' );
  41. const controller = editor.ui.featureComponents.create( 'headings' );
  42. const model = controller.model;
  43. model.id = 'foo';
  44. model.fire( 'execute' );
  45. sinon.assert.calledOnce( executeSpy );
  46. sinon.assert.calledWithExactly( executeSpy, 'heading', { formatId: 'foo' } );
  47. } );
  48. it( 'should focus view after command execution', () => {
  49. const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );
  50. const controller = editor.ui.featureComponents.create( 'headings' );
  51. const model = controller.model;
  52. model.fire( 'execute' );
  53. sinon.assert.calledOnce( focusSpy );
  54. } );
  55. describe( 'model to command binding', () => {
  56. let model, command;
  57. beforeEach( () => {
  58. model = controller.model;
  59. command = editor.commands.get( 'heading' );
  60. } );
  61. it( 'isEnabled', () => {
  62. expect( model.isEnabled ).to.be.true;
  63. command.isEnabled = false;
  64. expect( model.isEnabled ).to.be.false;
  65. } );
  66. it( 'label', () => {
  67. expect( model.label ).to.equal( 'Paragraph' );
  68. command.value = command.formats[ 1 ];
  69. expect( model.label ).to.equal( 'Heading 1' );
  70. } );
  71. } );
  72. } );