headings.js 2.6 KB

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