toolbarbindingsmixin.js 1.7 KB

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