8
0

componentfactory.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Editor from '@ckeditor/ckeditor5-core/src/editor/editor';
  6. import ComponentFactory from '../src/componentfactory';
  7. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  8. describe( 'ComponentFactory', () => {
  9. let editor, factory;
  10. beforeEach( () => {
  11. editor = new Editor();
  12. factory = new ComponentFactory( editor );
  13. } );
  14. describe( 'constructor()', () => {
  15. it( 'sets all the properties', () => {
  16. expect( factory ).to.have.property( 'editor', editor );
  17. } );
  18. } );
  19. describe( 'add', () => {
  20. it( 'throws when trying to override already registered component', () => {
  21. factory.add( 'foo', () => {} );
  22. expect( () => {
  23. factory.add( 'foo', () => {} );
  24. } ).to.throw( CKEditorError, /^componentfactory-item-exists/ );
  25. } );
  26. } );
  27. describe( 'create', () => {
  28. it( 'creates an instance', () => {
  29. class View {
  30. constructor( locale ) {
  31. this.locale = locale;
  32. }
  33. }
  34. const locale = editor.locale = {};
  35. factory.add( 'foo', locale => new View( locale ) );
  36. const instance = factory.create( 'foo' );
  37. expect( instance ).to.be.instanceof( View );
  38. expect( instance.locale ).to.equal( locale );
  39. } );
  40. } );
  41. } );