From abf32b8b21394491040e5c11c1fea809c1d7c62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 19 Nov 2018 08:18:28 +0000 Subject: [REF] *: update js test suite to use helpers This rev. introduces robust helpers to use in the JS tests suite to interact with DOM and components, and starts using them (almost) everywhere. All the helpers are exposed though testUtils.js. There are 2 kinds of helpers: 1. Assertions ------------- * assert.containsNone, containsN, containsOnce check that the DOM (or a specific part of the DOM) contains a `selector`. It generates a correct error message automatically. ex: assert.strictEqual(form.$('.o_form_editable'), 1, "msg"); -> assert.containsOnce(form, '.o_form_editable'); * assert.isVisible, isNotVisible check that the DOM has an element visible or not. They also check that the element is actually in the DOM (before most tests didn't verify this). * assert.hasClass, doesNotHaveClass, hasAttrVAlue, check specific properties of a DOM element, and also validate that it is applied on a single existing DOM element (before most tests didn't verify this). ex: assert.notOk(form.$('button').hasClass('btn-primary')); -> assert.doesNotHaveClass(form.$('button'), 'btn-primary'); 2. Utilities ------------ The goal of the utilities is to centralize the definition of many standard components and interactions, ensuring that when we refactor the JS framework, we do not need to change all the tests. Existing mock utilities (addMockEnvironment, intercept, path, patchDate, unpatch and fieldsViewGet) are moved to 'testUtils.mock.*'. Existing DOM utilities are moved to 'testUtils.dom.*'. New dom utilities are created for opendDatePicker, click, clickFirst and clickLast. Helper `click` verifies that there is exactly 1 element visible in the DOM you click on, `clickFirst` and `clickLast` verify that there are more than one element on the DOM. ex: form.$('button').click(); -> testUtils.dom.click(form.$('button')); New Form utilities: (testUtils.form.*) clickEdit, clickSave, clickCreate, clickDiscard, all clicks on the control panel buttons of the form. `reload` reloads the form data. New modal, graph, kanban and pivot utils (testUtils.pivot.*, testUtils.kanban.*, etc.). New fields utils: (testUtils.fields.*) * editInput, editSelect: allow to change the value of a field, using a selector to identify it. They validate that the input exists and trigger the change event automatically. * editAndTrigger: allow to modify a field and trigger specific events after the value change * many2one (testUtils.fields.many2one.*) clickOpenDropdown, clickHighlightedItem, clickItem, searchAndClickItem: use a field name instead of a selector and do all the complex mechanism to open, filter and highlight many2one fields. Joint work with aab, dam, ged, mge, svs and vsc. --- addons/web/static/src/js/tools/test_menus.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/tools/test_menus.js b/addons/web/static/src/js/tools/test_menus.js index e274839c48d..f7c5d61bc96 100644 --- a/addons/web/static/src/js/tools/test_menus.js +++ b/addons/web/static/src/js/tools/test_menus.js @@ -14,7 +14,7 @@ var Discuss = odoo.__DEBUG__.services['mail.Discuss']; var WebClient = odoo.__DEBUG__.services["web.WebClient"]; - WebClient.include({ + WebClient.include({ current_action_updated : function (action, controller) { this._super(action, controller); clientActionCount++; @@ -57,7 +57,7 @@ if (isEnterprise) { console.log("Odoo flavor: Enterprise") var $homeMenu = $("nav.o_main_navbar > a.o_menu_toggle.fa-th"); - $homeMenu.click() + testUtils.dom.click($homeMenu); $listOfAppMenuItems = $(".o_app, .o_menuitem") } else { console.log("Odoo flavor: Community") @@ -73,10 +73,10 @@ console.log("ok"); }).always(function() { console.log("Test took ", (performance.now() - startTime)/1000, " seconds"); - }).fail(function () { + }).fail(function () { console.error("Error !") }); - } + } /** @@ -101,7 +101,7 @@ }).then(function(){ // no effect in community var $homeMenu = $("nav.o_main_navbar > a.o_menu_toggle.fa-th"); - $homeMenu.click(); + testUtils.dom.click($homeMenu); }); } @@ -119,7 +119,7 @@ console.log("Testing menu", element.innerText.trim(), " ", element.dataset.menuXmlid); testedMenus.push(element.dataset.menuXmlid); var startActionCount = clientActionCount; - element.click(); + testUtils.dom.click(element); var isModal = false; return waitForCondition(function() { // sometimes, the app is just a modal that needs to be closed @@ -173,7 +173,7 @@ setTimeout(function() { var $element = $("nav.o_cp_switch_buttons > button[data-view-type=" + viewType + "]"); console.log('Clicking on: ', $element[0].dataset.viewType, ' view switcher'); - $element.click(); + testUtils.dom.click($element); },250); var waitViewSwitch = waitForCondition(function(){ return $('.o_content > .o_view_controller').data('view-type') === viewType; @@ -203,16 +203,16 @@ return $.Deferred().resolve(); }; console.log('Clicking on filter "', $filter.text().trim(), '"'); - $filter[0].click(); + testUtils.dom.click($filter[0]); setTimeout(function() { var $filterOption = $('.o_menu_item .o_item_option[data-item_id="' + filter_id + '"]:not(.selected) a'); // In case the filter is a date filter, we need to click on the first filter option (like 'today','This week' ...) if ($filterOption.length > 0) { console.log('Clicking on filter option "', $filterOption[0], '"'); - $filterOption[0].click(); + testUtils.dom.click($filterOption[0]); console.log('And now on filter again'); $filter = $('.o_menu_item[data-id="' + filter_id + '"] a'); - $filter[0].click(); // To avoid that the next view fold the options + testUtils.dom.click($filter[0]); } }, 250); return waitForCondition(function() { @@ -251,7 +251,7 @@ return def; }; - + /** * chain deferred actions * @param $elements: a list of jquery elements to be passed as arg to the function -- cgit v1.2.3