formats.js 2.2 KB

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