8
0

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