8
0

toolbarbindingsmixin.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: ui, toolbar */
  6. import mix from '/ckeditor5/utils/mix.js';
  7. import Editor from '/ckeditor5/editor/editor.js';
  8. import Controller from '/ckeditor5/ui/controller.js';
  9. import ToolbarBindingsMixin from '/ckeditor5/ui/bindings/toolbarbindingsmixin.js';
  10. describe( 'ToolbarBindingsMixin', () => {
  11. let mixinInstance, editor;
  12. beforeEach( () => {
  13. editor = new Editor();
  14. class MixClass extends Controller {
  15. constructor( model, view ) {
  16. super( model, view );
  17. this.addCollection( 'buttons' );
  18. }
  19. }
  20. mix( MixClass, ToolbarBindingsMixin );
  21. mixinInstance = new MixClass();
  22. mixinInstance.editor = editor;
  23. } );
  24. describe( 'addButtons', () => {
  25. it( 'creates buttons for each button name', () => {
  26. const createSpy = sinon.spy( () => new Controller() );
  27. editor.ui = {
  28. featureComponents: {
  29. create: createSpy
  30. }
  31. };
  32. mixinInstance.addButtons( [ 'foo', 'bar' ] );
  33. expect( createSpy.callCount ).to.equal( 2 );
  34. expect( createSpy.firstCall.calledWith( 'foo' ) ).to.be.true;
  35. expect( createSpy.secondCall.calledWith( 'bar' ) ).to.be.true;
  36. } );
  37. it( 'adds created components to the collection of buttons', () => {
  38. const component = new Controller();
  39. const createSpy = sinon.spy( () => component );
  40. editor.ui = {
  41. featureComponents: {
  42. create: createSpy
  43. }
  44. };
  45. mixinInstance.addButtons( [ 'foo' ] );
  46. expect( mixinInstance.collections.get( 'buttons' ).get( 0 ) ).to.equal( component );
  47. } );
  48. } );
  49. } );