componentfactory.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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', () => {} );
  23. expect( () => {
  24. factory.add( 'foo', () => {} );
  25. } ).to.throw( CKEditorError, /^componentfactory-item-exists/ );
  26. } );
  27. } );
  28. describe( 'create', () => {
  29. it( 'creates an instance', () => {
  30. class View {
  31. constructor( locale ) {
  32. this.locale = locale;
  33. }
  34. }
  35. const locale = editor.locale = {};
  36. factory.add( 'foo', locale => new View( locale ) );
  37. const instance = factory.create( 'foo' );
  38. expect( instance ).to.be.instanceof( View );
  39. expect( instance.locale ).to.equal( locale );
  40. } );
  41. } );
  42. } );