8
0

utils.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import View from '/ckeditor5/ui/view.js';
  6. import Controller from '/ckeditor5/ui/controller.js';
  7. /**
  8. * Test utils for CKEditor UI.
  9. */
  10. const utils = {
  11. /**
  12. * Returns UI controller for given region/DOM selector pairs, which {@link ui.Controller#view}
  13. * is `document.body`. It is useful for manual tests which engage various UI components and/or
  14. * UI {@link ui.Controller} instances, where initialization and the process of insertion into
  15. * DOM could be problematic i.e. because of the number of instances.
  16. *
  17. * Usage:
  18. *
  19. * // Get the controller.
  20. * const controller = testUtils.createTestUIController();
  21. *
  22. * // Then use it to organize and initialize children.
  23. * controller.add( 'some-collection', childControllerInstance );
  24. *
  25. * @param {Object} regions An object literal with `regionName: DOM Selector pairs`.
  26. * See {@link ui.View#register}.
  27. */
  28. createTestUIController( regions ) {
  29. const TestUIView = class extends View {
  30. constructor() {
  31. super();
  32. this.element = document.body;
  33. for ( let r in regions ) {
  34. this.register( r, regions[ r ] );
  35. }
  36. }
  37. };
  38. const controller = new Controller( null, new TestUIView() );
  39. for ( let r in regions ) {
  40. controller.addCollection( r );
  41. }
  42. return controller.init().then( () => {
  43. return controller;
  44. } );
  45. }
  46. };
  47. export default utils;