odoo-13.0/addons/web/static/tests/helpers/test_utils_create.js
/**
 * create a controlPanel from various parameters.
 *
 * It returns an instance of ControlPanelController
 *
 * @param {Object} [params={}]
 * @param {Object} [params.action={}]
 * @param {Object} [params.context={}]
 * @param {Object} [params.debug=false] if true, the widget will be appended in
 *   the DOM. Also, RPCs and uncaught OdooEvent will be logged
 * @param {string} [params.domain=[]]
 * @param {integer} [params.fieldDebounce=0] the debounce value to use for the
 *   duration of the test.
 * @param {Object} params.intercepts an object with event names as key, and
 *   callback as value.  Each key,value will be used to intercept the event.
 *   Note that this is particularly useful if you want to intercept events going
 *   up in the init process of the view, because there are no other way to do it
 *   after this method returns
 * @param {string} [params.modelName]
 * @param {string[]} [params.searchMenuTypes = ['filter', 'groupBy', 'favorite']]
 *   determines search menus displayed.
 * @param {string} [params.template] the QWeb template to render
 * @param {Object} [params.viewInfo={arch: '<controlpanel/>', fields: {}}]
     a controlpanel (or search) fieldsview
 * @param {string} [params.viewInfo.arch]
 * @param {boolean} [params.context.no_breadcrumbs=false] if set to true,
 *   breadcrumbs won't be rendered
 * @param {boolean} [params.withBreadcrumbs=true] if set to false,
 *   breadcrumbs won't be rendered
 * @param {boolean} [params.withSearchBar=true] if set to false, no default
 *   search bar will be rendered
 *
 * @returns {Promise<ControlPanel>} resolves with an instance of the ControlPanelController
 */
create a controlPanel from various parameters.
It returns an instance of ControlPanelController



@returns {Promise} resolves with an instance of the ControlPanelController
create a controlPanel from various parameters . It returns an instance of ControlPanelController @returns { Promise } resolves with an instance of the ControlPanelController
function createControlPanel(params) {
    params = params || {};
    var $target = $('#qunit-fixture');
    if (params.debug) {
        $target = $('body');
        $target.addClass('debug');
    }
    var $webClient = $('<div>').addClass('o_web_client').prependTo($target);
    var $actionManager = $('<div>').addClass('o_action_manager').appendTo($webClient);
    var $action = $('<div>').addClass('o_action').appendTo($actionManager);
    var widget = new Widget();
    var mockServer = testUtilsMock.addMockEnvironment(widget, params);
    if (!params.viewInfo) {
        try {
            params.viewInfo = testUtilsMock.fieldsViewGet(mockServer, params);
        } catch (e) {
        }
    }
    var viewOptions = _.defaults({}, params.viewOptions, {
        context: params.context,
        modelName: params.model,
        searchMenuTypes: params.searchMenuTypes,
        viewInfo: params.viewInfo,
    });
    var controlPanelView = new ControlPanelView(viewOptions);
    return controlPanelView.getController(widget).then(function (controlPanel) {
        controlPanel.__destroy = controlPanel.destroy;
        controlPanel.destroy = function () {
            delete controlPanel.destroy;
            widget.destroy();
            $webClient.remove();
        };
        var fragment = document.createDocumentFragment();
        return controlPanel.appendTo(fragment).then(function () {
            dom.prepend($action, fragment, {
                callbacks: [{ widget: controlPanel }],
                in_DOM: true,
            });
            return controlPanel;
        });
    });
}
function createControlPanel ( params ) { params = params || { } ; var $target = $ ( '#qunit-fixture' ) ; if ( params . debug ) { $target = $ ( 'body' ) ; $target . addClass ( 'debug' ) ; } var $webClient = $ ( '<div>' ) . addClass ( 'o_web_client' ) . prependTo ( $target ) ; var $actionManager = $ ( '<div>' ) . addClass ( 'o_action_manager' ) . appendTo ( $webClient ) ; var $action = $ ( '<div>' ) . addClass ( 'o_action' ) . appendTo ( $actionManager ) ; var widget = new Widget ( ) ; var mockServer = testUtilsMock . addMockEnvironment ( widget , params ) ; if ( ! params . viewInfo ) { try { params . viewInfo = testUtilsMock . fieldsViewGet ( mockServer , params ) ; } catch ( e ) { } } var viewOptions = _ . defaults ( { } , params . viewOptions , { context : params . context , modelName : params . model , searchMenuTypes : params . searchMenuTypes , viewInfo : params . viewInfo , } ) ; var controlPanelView = new ControlPanelView ( viewOptions ) ; return controlPanelView . getController ( widget ) . then ( function ( controlPanel ) { controlPanel . __destroy = controlPanel . destroy ; controlPanel . destroy = function ( ) { delete controlPanel . destroy ; widget . destroy ( ) ; $webClient . remove ( ) ; } ; var fragment = document . createDocumentFragment ( ) ; return controlPanel . appendTo ( fragment ) . then ( function ( ) { dom . prepend ( $action , fragment , { callbacks : [ { widget : controlPanel } ] , in_DOM : true , } ) ; return controlPanel ; } ) ; } ) ; }
create a controlPanel from various parameters.
create a controlPanel from various parameters .
// reproduce the DOM environment of a view control panel // add mock environment: mock server, session, fieldviewget, ... // if an error occurs we keep params.viewInfo undefined. // It will be set to {arch: '<controlpanel/>', fields: {}} in // ControlPanelView init function. // override the controlPanel's 'destroy' so that it calls 'destroy' on // the widget instead, as the widget is the parent of the controlPanel // and the mockServer. // remove the override to properly destroy the controlPanel and its // children when it will be called the second time (by its parent) // render the controlPanel in a fragment as it must be able to render // correctly without being in the DOM