diff options
Diffstat (limited to 'addons/web/static/src/js/tools/test_menus.js')
| -rw-r--r-- | addons/web/static/src/js/tools/test_menus.js | 109 |
1 files changed, 56 insertions, 53 deletions
diff --git a/addons/web/static/src/js/tools/test_menus.js b/addons/web/static/src/js/tools/test_menus.js index 4e31b2d4467..d950d5d56ee 100644 --- a/addons/web/static/src/js/tools/test_menus.js +++ b/addons/web/static/src/js/tools/test_menus.js @@ -65,16 +65,16 @@ } console.log('Found ', $listOfAppMenuItems.length, 'apps to test'); - var testDef = $.when(); - testDef = chainDeferred($listOfAppMenuItems, testDef, testApp); - return testDef.then(function() { + var testPromise = Promise.resolve(); + testPromise = chainDeferred($listOfAppMenuItems, testPromise, testApp); + return testPromise.then(function () { console.log("Successfully tested ", testedApps.length, " apps"); console.log("Successfully tested ", testedMenus.length - testedApps.length, " menus"); console.log("test successful"); - }).always(function() { - console.log("Test took ", (performance.now() - startTime)/1000, " seconds"); - }).fail(function () { - console.error("test failed"); + console.log("Test took ", (performance.now() - startTime) / 1000, " seconds"); + }).catch(function () { + console.log("Test took ", (performance.now() - startTime) / 1000, " seconds"); + console.error("Error !"); }); } @@ -86,18 +86,18 @@ * 3 - clicking on each menu * 3.1 - clicking on each view * @param {DomElement} element: the App menu item - * @returns {Deferred} + * @returns {Promise} */ function testApp(element){ console.log("Testing app menu:", element.dataset.menuXmlid); - if (testedApps.indexOf(element.dataset.menuXmlid) >= 0) return $.Deferred().resolve(); // Another infinite loop protection + if (testedApps.indexOf(element.dataset.menuXmlid) >= 0) return Promise.resolve(); // Another infinite loop protection testedApps.push(element.dataset.menuXmlid); return testMenuItem(element).then(function () { var $subMenuItems; $subMenuItems = $('.o_menu_entry_lvl_1, .o_menu_entry_lvl_2, .o_menu_entry_lvl_3, .o_menu_entry_lvl_4'); - var testMenuDef = $.when(); - testMenuDef = chainDeferred($subMenuItems, testMenuDef, testMenuItem); - return testMenuDef; + var testMenuPromise = Promise.resolve(); + testMenuPromise = chainDeferred($subMenuItems, testMenuPromise, testMenuItem); + return testMenuPromise; }).then(function(){ // no effect in community var $homeMenu = $("nav.o_main_navbar > a.o_menu_toggle.fa-th"); @@ -112,10 +112,10 @@ * 2 - Orchestrate the view switch * * @param {DomElement} element: the menu item - * @returns {Deferred} + * @returns {Promise} */ function testMenuItem(element){ - if (testedMenus.indexOf(element.dataset.menuXmlid) >= 0) return $.Deferred().resolve(); // Avoid infinite loop + if (testedMenus.indexOf(element.dataset.menuXmlid) >= 0) return Promise.resolve(); // Avoid infinite loop console.log("Testing menu", element.innerText.trim(), " ", element.dataset.menuXmlid); testedMenus.push(element.dataset.menuXmlid); var startActionCount = clientActionCount; @@ -128,7 +128,7 @@ $modal.modal('hide'); isModal = true; return true; - }; + } return startActionCount != clientActionCount; }).then(function() { if (!isModal) { @@ -138,7 +138,7 @@ if (!isModal) { return testViews(); } - }).fail(function() { + }).catch(function () { console.error("Error while testing", element); }); }; @@ -151,21 +151,21 @@ */ function testViews() { var $switches = $("nav.o_cp_switch_buttons > button:not(.active):visible"); - var testSwitchDef = $.when(); - // chainDeferred($switches, testSwitchDef, testViewSwitch # FIXME + var testSwitchPromise = Promise.resolve(); + // chainDeferred($switches, testSwitchPromise, testViewSwitch # FIXME _.each($switches, function(switchButton) { - testSwitchDef = testSwitchDef.then(function () { + testSwitchPromise = testSwitchPromise.then(function () { // get the view view-type data attribute return testViewSwitch(switchButton.dataset.viewType); }); }); - return testSwitchDef; + return testSwitchPromise; } /** * Test a view button * @param {string} viewType: a string for the view type to test (list, kanban ...) - * @returns {Deferred} a deferred that wait for the view to be loaded + * @returns {Promise} a promise that wait for the view to be loaded */ function testViewSwitch(viewType){ console.log("Testing view switch: ", viewType); @@ -188,20 +188,20 @@ * Click on each filter in the control pannel */ function testFilters() { - var filterDef = $.when(); + var filterProm = Promise.resolve(); // var $filters = $('div.o_control_panel div.btn-group.o_dropdown > ul.o_filters_menu > li:not(.o_add_custom_filter)'); var $filters = $('.o_filters_menu > .o_menu_item'); console.log("Testing " + $filters.length + " filters"); var filter_ids = _.compact(_.map($filters, function(f) { return f.dataset.id})); _.each(filter_ids, function(filter_id){ - filterDef = filterDef.then(function(){ + filterProm = filterProm.then(function(){ var currentViewCount = viewUpdateCount; var $filter = $('.o_menu_item[data-id="' + filter_id + '"] a'); // with some customized search views, the filter cannot be found if ($filter[0] === undefined) { console.warn('Filter with ID ', filter_id , 'cannot be found'); - return $.Deferred().resolve(); - }; + return Promise.resolve(); + } console.log('Clicking on filter "', $filter.text().trim(), '"'); $filter[0].click(); setTimeout(function() { @@ -220,52 +220,55 @@ }); }); }); - return filterDef; + return filterProm; } // utility functions /** * Wait a certain amount of time for a condition to occur - * @param stopCondition: a function that returns a boolean - * @returns {Deferred} that is rejected if the timeout is exceeded + * @param {function} stopCondition a function that returns a boolean + * @returns {Promise} that is rejected if the timeout is exceeded */ function waitForCondition(stopCondition) { - var def = $.Deferred(); - var interval = 250; - var timeLimit = 15000; - function checkCondition() { - if (stopCondition()) { - def.resolve(); - } else { - timeLimit -= interval; - if (timeLimit > 0) { - // recursive call until the resolve or the timeout - setTimeout(checkCondition, interval); + var prom = new Promise(function (resolve, reject) { + var interval = 250; + var timeLimit = 15000; + + function checkCondition() { + if (stopCondition()) { + resolve(); } else { - console.error("Timeout exceeded", stopCondition); - def.reject(); + timeLimit -= interval; + if (timeLimit > 0) { + // recursive call until the resolve or the timeout + setTimeout(checkCondition, interval); + } else { + console.error("Timeout exceeded", stopCondition); + reject(); + } } } - } - setTimeout(checkCondition, interval); - return def; - }; + setTimeout(checkCondition, interval); + }); + return prom; + } /** - * chain deferred actions - * @param $elements: a list of jquery elements to be passed as arg to the function - * @param deferred: the deferred on which other deferreds will be chained - * @param f: the function to be deferred - * @returns : the chained deferred + * Chain deferred actions. + * + * @param {jQueryElement} $elements a list of jquery elements to be passed as arg to the function + * @param {Promise} promise the promise on which other promises will be chained + * @param {function} f the function to be deferred + * @returns {Promise} the chained promise */ - function chainDeferred($elements, deferred, f) { + function chainDeferred($elements, promise, f) { _.each($elements, function(el) { - deferred = deferred.then(function () { + promise = promise.then(function () { return f(el); }); }); - return deferred; + return promise; } |
