summaryrefslogtreecommitdiff
path: root/addons/partner_autocomplete
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2018-11-19 08:18:28 +0000
committerAaron Bohy <aab@odoo.com>2018-11-19 11:24:28 +0000
commitabf32b8b21394491040e5c11c1fea809c1d7c62c (patch)
tree6058f8a893815bf0ed2495649c125523f4def762 /addons/partner_autocomplete
parentbcbb7ee3fecaad3c7e801fa5dbc90a566faac27f (diff)
[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.
Diffstat (limited to 'addons/partner_autocomplete')
-rw-r--r--addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js40
1 files changed, 20 insertions, 20 deletions
diff --git a/addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js b/addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js
index 9a49acd846f..52dcde5370f 100644
--- a/addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js
+++ b/addons/partner_autocomplete/static/tests/partner_autocomplete_tests.js
@@ -17,7 +17,7 @@ odoo.define('partner_autocomplete.tests', function (require) {
if (fields[key]) {
if (key === 'image') {
if (val) val = 'data:image/png;base64,' + val;
- assert.strictEqual(form.$(".o_field_image img").attr("data-src"), val, 'image value should have been updated to "' + val + '"');
+ assert.hasAttrValue(form.$(".o_field_image img"), "data-src", val, 'image value should have been updated to "' + val + '"');
} else {
type = fields[key].type;
$fieldInput = form.$('input[name="' + key + '"]');
@@ -56,7 +56,7 @@ odoo.define('partner_autocomplete.tests', function (require) {
vat: "BE0477472701",
};
- testUtils.patch(AutocompleteCore, {
+ testUtils.mock.patch(AutocompleteCore, {
_getBase64Image: function (url) {
return $.when(url === "odoo.com/logo.png" ? "odoobase64" : "");
},
@@ -87,7 +87,7 @@ odoo.define('partner_autocomplete.tests', function (require) {
},
});
- testUtils.patch(AutocompleteField, {
+ testUtils.mock.patch(AutocompleteField, {
debounceSuggestions: 0,
});
},
@@ -127,8 +127,8 @@ odoo.define('partner_autocomplete.tests', function (require) {
};
},
after: function () {
- testUtils.unpatch(AutocompleteField);
- testUtils.unpatch(AutocompleteCore);
+ testUtils.mock.unpatch(AutocompleteField);
+ testUtils.mock.unpatch(AutocompleteCore);
},
});
@@ -149,14 +149,14 @@ odoo.define('partner_autocomplete.tests', function (require) {
}).then(function (form){
// Set company type to Individual
var $company_type = form.$("select[name='company_type']");
- $company_type.val('"individual"').trigger('change');
+ testUtils.fields.editSelect($company_type, '"individual"');
// Check input exists
var $input = form.$(".o_field_partner_autocomplete > input:visible");
assert.strictEqual($input.length, 1, "there should be an <input/> for the Partner field");
// Change input val and assert nothing happens
- $input.val("odoo").trigger("input");
+ testUtils.fields.editInput($input, "odoo")
var $dropdown = form.$(".o_field_partner_autocomplete .dropdown-menu:visible");
assert.strictEqual($dropdown.length, 0, "there should not be an opened dropdown");
@@ -205,20 +205,20 @@ odoo.define('partner_autocomplete.tests', function (require) {
}).then(function (form){
// Set company type to Company
var $company_type = form.$("select[name='company_type']");
- $company_type.val('"company"').trigger('change');
+ testUtils.fields.editSelect($company_type, '"company"');
// Check input exists
var $input = form.$(".o_field_partner_autocomplete > input:visible");
assert.strictEqual($input.length, 1, "there should be an <input/> for the field");
// Change input val and assert changes
- $input.val("odoo").trigger("input");
+ testUtils.fields.editInput($input, "odoo")
var $dropdown = form.$(".o_field_partner_autocomplete .dropdown-menu:visible");
assert.strictEqual($dropdown.length, 1, "there should be an opened dropdown");
assert.strictEqual($dropdown.children().length, 1, "there should be only one proposition");
- $dropdown.find("a").first().click();
+ testUtils.dom.click($dropdown.find("a").first());
$input = form.$(".o_field_partner_autocomplete > input");
assert.strictEqual($input.val(), "Odoo", "Input value should have been updated to \"Odoo\"");
assert.strictEqual(form.$("input.o_field_widget").val(), "odoo.com", "website value should have been updated to \"odoo.com\"");
@@ -226,12 +226,12 @@ odoo.define('partner_autocomplete.tests', function (require) {
_compareResultFields(assert, form, fields, AutocompleteCore._createData);
// Try suggestion with bullshit query
- $input.val("ZZZZZZZZZZZZZZZZZZZZZZ").trigger("input");
+ testUtils.fields.editInput($input, "ZZZZZZZZZZZZZZZZZZZZZZ")
$dropdown = form.$(".o_field_partner_autocomplete .dropdown-menu:visible");
assert.strictEqual($dropdown.length, 0, "there should be no opened dropdown when no result");
// Try autocomplete again
- $input.val("odoo").trigger("input");
+ testUtils.fields.editInput($input, "odoo")
$dropdown = form.$(".o_field_partner_autocomplete .dropdown-menu:visible");
assert.strictEqual($dropdown.length, 1, "there should be an opened dropdown when typing odoo letters again");
@@ -284,7 +284,7 @@ odoo.define('partner_autocomplete.tests', function (require) {
}).then(function (form){
// Set company type to Company
var $company_type = form.$("select[name='company_type']");
- $company_type.val('"company"').trigger('change');
+ testUtils.fields.editSelect($company_type, '"company"');
// Check input exists
@@ -292,19 +292,19 @@ odoo.define('partner_autocomplete.tests', function (require) {
assert.strictEqual($input.length, 1, "there should be an <input/> for the field");
// Set incomplete VAT and assert changes
- $input.val("BE047747270").trigger("input");
+ testUtils.fields.editInput($input, "BE047747270")
var $dropdown = form.$(".o_field_partner_autocomplete .dropdown-menu:visible");
assert.strictEqual($dropdown.length, 0, "there should be no opened dropdown no results with incomplete VAT number");
// Set complete VAT and assert changes
// First suggestion (only vat result)
- $input.val("BE0477472701").trigger("input");
+ testUtils.fields.editInput($input, "BE0477472701")
$dropdown = form.$(".o_field_partner_autocomplete .dropdown-menu:visible");
assert.strictEqual($dropdown.length, 1, "there should be an opened dropdown");
assert.strictEqual($dropdown.children().length, 1, "there should be one proposition for complete VAT number");
- $dropdown.find("a").first().click();
+ testUtils.dom.click($dropdown.find("a").first());
$input = form.$(".o_field_partner_autocomplete > input");
assert.strictEqual($input.val(), "Odoo", "Input value should have been updated to \"Odoo\"");
@@ -313,12 +313,12 @@ odoo.define('partner_autocomplete.tests', function (require) {
// Set complete VAT and assert changes
// Second suggestion (only vat + clearbit result)
- $input.val("BE0477472701").trigger("input");
+ testUtils.fields.editInput($input, "BE0477472701")
$dropdown = form.$(".o_field_partner_autocomplete .dropdown-menu:visible");
assert.strictEqual($dropdown.length, 1, "there should be an opened dropdown");
assert.strictEqual($dropdown.children().length, 1, "there should be one proposition for complete VAT number");
- $dropdown.find("a").first().click();
+ testUtils.dom.click($dropdown.find("a").first());
$input = form.$(".o_field_partner_autocomplete > input");
assert.strictEqual($input.val(), "Odoo", "Input value should have been updated to \"Odoo\"");
@@ -356,12 +356,12 @@ odoo.define('partner_autocomplete.tests', function (require) {
var $input = form.$('.o_field_many2one[name="parent_id"] input:visible');
assert.strictEqual($input.length, 1, "there should be an <input/> for the Many2one");
- $input.val('odoo').trigger('input');
+ testUtils.fields.editInput($input, 'odoo');
concurrency.delay(0).then(function () {
var $dropdown = $input.autocomplete('widget');
assert.strictEqual($dropdown.length, 1, "there should be an opened dropdown");
- assert.ok($dropdown.is('.o_partner_autocomplete_dropdown'),
+ assert.ok($dropdown.is('.o_partner_autocomplete_dropdown'),
"there should be a partner_autocomplete");
PartnerField.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;