8
0

formats.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. const editorElement = document.createElement( 'div' );
  16. document.body.appendChild( editorElement );
  17. return ClassicTestEditor.create( editorElement, {
  18. features: [ Formats ],
  19. toolbar: [ 'formats' ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. controller = editor.ui.featureComponents.create( 'formats' );
  24. } );
  25. } );
  26. afterEach( () => {
  27. return editor.destroy();
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( Formats ) ).to.be.instanceOf( Formats );
  31. } );
  32. it( 'should load FormatsEngine', () => {
  33. expect( editor.plugins.get( FormatsEngine ) ).to.be.instanceOf( FormatsEngine );
  34. } );
  35. it( 'should register formats feature component', () => {
  36. const controller = editor.ui.featureComponents.create( 'formats' );
  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( 'formats' );
  42. const model = controller.model.content;
  43. model.fire( 'execute', { id: 'paragraph', label: 'Paragraph' } );
  44. sinon.assert.calledOnce( executeSpy );
  45. sinon.assert.calledWithExactly( executeSpy, 'format', 'paragraph' );
  46. } );
  47. describe( 'model to commanad binding', () => {
  48. let model, command;
  49. beforeEach( () => {
  50. model = controller.model;
  51. command = editor.commands.get( 'format' );
  52. } );
  53. it( 'isEnabled', () => {
  54. expect( model.isEnabled ).to.be.true;
  55. command.isEnabled = false;
  56. expect( model.isEnabled ).to.be.false;
  57. } );
  58. it( 'label', () => {
  59. expect( model.label ).to.equal( 'Paragraph' );
  60. command.value = command.formats[ 1 ];
  61. expect( model.label ).to.equal( 'Heading 1' );
  62. } );
  63. } );
  64. } );