8
0

headings.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Headings from '/ckeditor5/headings/headings.js';
  8. import HeadingsEngine from '/ckeditor5/headings/headingsengine.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( 'Headings', () => {
  13. let editor, controller;
  14. beforeEach( () => {
  15. const editorElement = document.createElement( 'div' );
  16. document.body.appendChild( editorElement );
  17. return ClassicTestEditor.create( editorElement, {
  18. features: [ Headings ],
  19. toolbar: [ 'headings' ]
  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( Headings ) ).to.be.instanceOf( Headings );
  31. } );
  32. it( 'should load FormatsEngine', () => {
  33. expect( editor.plugins.get( HeadingsEngine ) ).to.be.instanceOf( HeadingsEngine );
  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.content;
  43. model.fire( 'execute', { id: 'paragraph', label: 'Paragraph' } );
  44. sinon.assert.calledOnce( executeSpy );
  45. sinon.assert.calledWithExactly( executeSpy, 'headings', 'paragraph' );
  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.content;
  51. model.fire( 'execute', { id: 'paragraph', label: 'Paragraph' } );
  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. } );