getitemsfromconfig.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import View from '../../src/view';
  7. import ComponentFactory from '../../src/componentfactory';
  8. import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
  9. import Collection from '@ckeditor/ckeditor5-utils/src/collection';
  10. import ToolbarSeparatorView from '../../src/toolbar/toolbarseparatorview';
  11. import getItemsFromConfig from '../../src/toolbar/getitemsfromconfig';
  12. describe( 'getItemsFromConfig()', () => {
  13. let factory;
  14. beforeEach( () => {
  15. factory = new ComponentFactory( new Editor() );
  16. factory.add( 'foo', viewCreator( 'foo' ) );
  17. factory.add( 'bar', viewCreator( 'bar' ) );
  18. } );
  19. it( 'returns a promise', () => {
  20. expect( getItemsFromConfig() ).to.be.instanceOf( Promise );
  21. } );
  22. it( 'expands the config into collection', () => {
  23. const collection = new Collection();
  24. return getItemsFromConfig( [ 'foo', 'bar', '|', 'foo' ], collection, factory )
  25. .then( () => {
  26. expect( collection ).to.have.length( 4 );
  27. expect( collection.get( 0 ).name ).to.equal( 'foo' );
  28. expect( collection.get( 1 ).name ).to.equal( 'bar' );
  29. expect( collection.get( 2 ) ).to.be.instanceOf( ToolbarSeparatorView );
  30. expect( collection.get( 3 ).name ).to.equal( 'foo' );
  31. } );
  32. } );
  33. } );
  34. function viewCreator( name ) {
  35. return ( locale ) => {
  36. const view = new View( locale );
  37. view.name = name;
  38. view.element = document.createElement( 'a' );
  39. return view;
  40. };
  41. }