| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* globals document */
- import View from 'ckeditor5/ui/view.js';
- /**
- * Test utils for CKEditor UI.
- */
- const utils = {
- /**
- * Returns UI controller for given region/DOM selector pairs, which {@link ui.Controller#view}
- * is `document.body`. It is useful for manual tests which engage various UI components and/or
- * UI {@link ui.Controller} instances, where initialization and the process of insertion into
- * DOM could be problematic i.e. because of the number of instances.
- *
- * Usage:
- *
- * // Get the controller.
- * const controller = testUtils.createTestUIView();
- *
- * // Then use it to organize and initialize children.
- * controller.add( 'some-collection', childControllerInstance );
- *
- * @param {Object} regions An object literal with `regionName: [DOM Selector|callback]` pairs.
- * See {@link ui.View#register}.
- */
- createTestUIView( regions ) {
- const TestUIView = class extends View {
- constructor() {
- super();
- this.element = document.body;
- for ( let name in regions ) {
- const regionCollection = this[ name ] = this.createCollection();
- const callbackOrSelector = regions[ name ];
- regionCollection.setParent(
- typeof callbackOrSelector == 'string' ?
- document.querySelector( callbackOrSelector )
- :
- callbackOrSelector( this.element )
- );
- }
- }
- };
- const view = new TestUIView();
- return view.init().then( () => {
- return view;
- } );
- }
- };
- export default utils;
|