toolbar.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. view = new View( model );
  18. toolbar = new Toolbar( model, view, editor );
  19. } );
  20. describe( 'constructor', () => {
  21. it( 'sets all the properties', () => {
  22. expect( toolbar ).to.have.property( 'editor', editor );
  23. } );
  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. toolbar.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. toolbar.addButtons( [ 'foo' ] );
  47. expect( toolbar.collections.get( 'buttons' ).get( 0 ) ).to.equal( component );
  48. } );
  49. } );
  50. } );