componentfactory.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
  9. describe( 'ComponentFactory', () => {
  10. let editor, factory;
  11. beforeEach( () => {
  12. editor = new Editor();
  13. factory = new ComponentFactory( editor );
  14. } );
  15. describe( 'constructor', () => {
  16. it( 'sets all the properties', () => {
  17. expect( factory ).to.have.property( 'editor', editor );
  18. } );
  19. } );
  20. describe( 'add', () => {
  21. it( 'throws when trying to override already registered component', () => {
  22. factory.add( 'foo', class {}, class {}, {} );
  23. expect( () => {
  24. factory.add( 'foo', class {}, class {}, {} );
  25. } ).to.throw( CKEditorError, /^componentfactory-item-exists/ );
  26. } );
  27. } );
  28. describe( 'create', () => {
  29. it( 'creates an instance', () => {
  30. class View {}
  31. class Controller {
  32. constructor( model, view, ed ) {
  33. expect( model ).to.equal( model );
  34. expect( view ).to.be.instanceof( View );
  35. expect( ed ).to.equal( editor );
  36. }
  37. }
  38. const model = {};
  39. factory.add( 'foo', Controller, View, model );
  40. const instance = factory.create( 'foo' );
  41. expect( instance ).to.be.instanceof( Controller );
  42. } );
  43. } );
  44. } );