toolbarbindingsmixin.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: ui, mixinInstance */
  6. 'use strict';
  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( 'StickyToolbar', () => {
  12. let mixinInstance, editor;
  13. beforeEach( () => {
  14. editor = new Editor();
  15. mixinInstance = new Controller();
  16. mixinInstance.collections.add( new ControllerCollection( 'buttons' ) );
  17. mixinInstance.editor = editor;
  18. Object.assign( mixinInstance, ToolbarBindingsMixin );
  19. } );
  20. describe( 'addButtons', () => {
  21. it( 'creates buttons for each button name', () => {
  22. const createSpy = sinon.spy( () => new Controller() );
  23. editor.ui = {
  24. featureComponents: {
  25. create: createSpy
  26. }
  27. };
  28. mixinInstance.addButtons( [ 'foo', 'bar' ] );
  29. expect( createSpy.callCount ).to.equal( 2 );
  30. expect( createSpy.firstCall.calledWith( 'foo' ) ).to.be.true;
  31. expect( createSpy.secondCall.calledWith( 'bar' ) ).to.be.true;
  32. } );
  33. it( 'adds created components to the collection of buttons', () => {
  34. const component = new Controller();
  35. const createSpy = sinon.spy( () => component );
  36. editor.ui = {
  37. featureComponents: {
  38. create: createSpy
  39. }
  40. };
  41. mixinInstance.addButtons( [ 'foo' ] );
  42. expect( mixinInstance.collections.get( 'buttons' ).get( 0 ) ).to.equal( component );
  43. } );
  44. } );
  45. } );