odoo-13.0/addons/web/static/tests/helpers/test_utils_fields.js
/**
 * This helper is useful to test many2one fields. Here is what it does:
 * - click to open the dropdown
 * - enter a search string in the input
 * - wait for the selection
 * - click on the requested menuitem, or the active one by default
 *
 * Example:
 *    testUtils.fields.many2one.searchAndClickM2OItem('partner_id', {search: 'George'});
 *
 * @param {string} fieldName
 * @param {[Object]} options
 * @param {[string]} options.selector
 * @param {[string]} options.search
 * @param {[string]} options.item
 * @returns {Promise}
 */
This helper is useful to test many2one fields. Here is what it does:
- click to open the dropdown
- enter a search string in the input
- wait for the selection
- click on the requested menuitem, or the active one by default




This helper is useful to test many2one fields . Here is what it does : - click to open the dropdown - enter a search string in the input - wait for the selection - click on the requested menuitem or the active one by default
function searchAndClickM2OItem(fieldName, options) {
    options = options || {};
    return clickOpenM2ODropdown(fieldName, options.selector).then(function (input) {
        var def;
        if (options.search) {
            input.value = options.search;
            input.dispatchEvent(new Event('input'));
            def = concurrency.delay(0);
        }
        return Promise.resolve(def).then(function () {
            if (options.item) {
                return clickM2OItem(fieldName, options.item);
            } else {
                return clickM2OHighlightedItem(fieldName, options.selector);
            }
        });
    });
}
function searchAndClickM2OItem ( fieldName , options ) { options = options || { } ; return clickOpenM2ODropdown ( fieldName , options . selector ) . then ( function ( input ) { var def ; if ( options . search ) { input . value = options . search ; input . dispatchEvent ( new Event ( 'input' ) ) ; def = concurrency . delay ( 0 ) ; } return Promise . resolve ( def ) . then ( function ( ) { if ( options . item ) { return clickM2OItem ( fieldName , options . item ) ; } else { return clickM2OHighlightedItem ( fieldName , options . selector ) ; } } ) ; } ) ; }
This helper is useful to test many2one fields.
This helper is useful to test many2one fields .