toolbarbindingsmixin.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 ControllerCollection from '/ckeditor5/ui/controllercollection.js';
  10. import ToolbarBindingsMixin from '/ckeditor5/ui/bindings/toolbarbindingsmixin.js';
  11. describe( 'ToolbarBindingsMixin', () => {
  12. let mixinInstance, editor;
  13. beforeEach( () => {
  14. editor = new Editor();
  15. class MixClass extends Controller {
  16. constructor( model, view ) {
  17. super( model, view );
  18. this.collections.add( new ControllerCollection( 'buttons' ) );
  19. }
  20. }
  21. mix( MixClass, ToolbarBindingsMixin );
  22. mixinInstance = new MixClass();
  23. mixinInstance.editor = editor;
  24. } );
  25. describe( 'addButtons', () => {
  26. it( 'creates buttons for each button name', () => {
  27. const createSpy = sinon.spy( () => new Controller() );
  28. editor.ui = {
  29. featureComponents: {
  30. create: createSpy
  31. }
  32. };
  33. mixinInstance.addButtons( [ 'foo', 'bar' ] );
  34. expect( createSpy.callCount ).to.equal( 2 );
  35. expect( createSpy.firstCall.calledWith( 'foo' ) ).to.be.true;
  36. expect( createSpy.secondCall.calledWith( 'bar' ) ).to.be.true;
  37. } );
  38. it( 'adds created components to the collection of buttons', () => {
  39. const component = new Controller();
  40. const createSpy = sinon.spy( () => component );
  41. editor.ui = {
  42. featureComponents: {
  43. create: createSpy
  44. }
  45. };
  46. mixinInstance.addButtons( [ 'foo' ] );
  47. expect( mixinInstance.collections.get( 'buttons' ).get( 0 ) ).to.equal( component );
  48. } );
  49. } );
  50. } );