componentfactory.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: ui */
  6. import Editor from '/ckeditor5/core/editor/editor.js';
  7. import ComponentFactory from '/ckeditor5/ui/componentfactory.js';
  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', class {}, class {}, {} );
  22. expect( () => {
  23. factory.add( 'foo', class {}, class {}, {} );
  24. } ).to.throwCKEditorError( /^componentfactory-item-exists/ );
  25. } );
  26. } );
  27. describe( 'create', () => {
  28. it( 'creates an instance', () => {
  29. class View {}
  30. class Controller {
  31. constructor( model, view, ed ) {
  32. expect( model ).to.equal( model );
  33. expect( view ).to.be.instanceof( View );
  34. expect( ed ).to.equal( editor );
  35. }
  36. }
  37. const model = {};
  38. factory.add( 'foo', Controller, View, model );
  39. const instance = factory.create( 'foo' );
  40. expect( instance ).to.be.instanceof( Controller );
  41. } );
  42. } );
  43. } );