8
0

componentfactory.js 1.4 KB

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