8
0

utils.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/utils';
  12. describe( 'utils', () => {
  13. describe( 'getItemsFromConfig()', () => {
  14. let factory;
  15. beforeEach( () => {
  16. factory = new ComponentFactory( new Editor() );
  17. factory.add( 'foo', viewCreator( 'foo' ) );
  18. factory.add( 'bar', viewCreator( 'bar' ) );
  19. } );
  20. it( 'returns a promise', () => {
  21. expect( getItemsFromConfig() ).to.be.instanceOf( Promise );
  22. } );
  23. it( 'expands the config into collection', () => {
  24. const collection = new Collection();
  25. return getItemsFromConfig( [ 'foo', 'bar', '|', 'foo' ], collection, factory )
  26. .then( () => {
  27. expect( collection ).to.have.length( 4 );
  28. expect( collection.get( 0 ).name ).to.equal( 'foo' );
  29. expect( collection.get( 1 ).name ).to.equal( 'bar' );
  30. expect( collection.get( 2 ) ).to.be.instanceOf( ToolbarSeparatorView );
  31. expect( collection.get( 3 ).name ).to.equal( 'foo' );
  32. } );
  33. } );
  34. } );
  35. } );
  36. function viewCreator( name ) {
  37. return ( locale ) => {
  38. const view = new View( locale );
  39. view.name = name;
  40. view.element = document.createElement( 'a' );
  41. return view;
  42. };
  43. }